def test_to_period_tz_warning(self): # GH#21333 make sure a warning is issued when timezone # info is lost ts = Timestamp('2009-04-15 16:17:18', tz='US/Eastern') with tm.assert_produces_warning(UserWarning): # warning that timezone info will be lost ts.to_period('D')
def test_to_period_tz_warning(self): # GH#21333 make sure a warning is issued when timezone # info is lost ts = Timestamp("2009-04-15 16:17:18", tz="US/Eastern") with tm.assert_produces_warning(UserWarning): # warning that timezone info will be lost ts.to_period("D")
def finance_report(start: Timestamp, end: Timestamp, market: str, symbol: str, report_type: str, quarter="all") -> DataFrame: """ :param start: start time :param end: end time :param market: {'HK', 'CN'} :param symbol: stock symbol :param report_type: {'indicator', 'balance', 'income', 'business'} :param quarter: {'all', 'Q1', 'Q2', ‘Q3', 'Q4'} :return: data frame contains items of financial report """ count = (end.to_period(freq='Q') - start.to_period(freq='Q')).n end_timestamp = int(end.timestamp() * 1000) urlpath = f"{market}/{report_type}.json?symbol={symbol}&&type={quarter}" \ f"&is_detail=true&count={count}×tamp={end_timestamp}" url = urljoin(api_ref.finance_base, urlpath) data = utls.fetch(url) data_list = data.pop('list') for d in data_list: for k in d: if isinstance(d[k], list): d[k] = d[k][0] df = DataFrame(data_list).drop(columns=['ctime']).rename( columns={ 'report_date': 'date' }).set_index('date') df.date = df.date.astype('M8[ms]') df.report_name = df.report_name.str.replace('年报', 'Q4').str.replace('三季报', 'Q3')\ .str.replace('中报', 'Q2').str.replace('一季报', 'Q1') return df
def _range_from_time_index(self, start: pd.Timestamp, stop: pd.Timestamp) -> pd.DataFrame: index = self._index if isinstance(self._index, pd.PeriodIndex): if isinstance(start, pd.Timestamp): start = start.to_period(freq=self._index_freq) if isinstance(stop, pd.Timestamp): stop = stop.to_period(freq=self._index_freq) if start < index[0]: raise ValueError(START_BEFORE_INDEX_ERR) if stop <= self._index[-1]: return self.in_sample().loc[start:stop] new_idx = self._extend_time_index(stop) oos_idx = new_idx[new_idx > index[-1]] oos = self.out_of_sample(oos_idx.shape[0], oos_idx) if start >= oos_idx[0]: return oos.loc[start:stop] both = pd.concat([self.in_sample(), oos], axis=0) return both.loc[start:stop]
def test_td64arr_sub_pi(self, box, tdi_freq, pi_freq): # GH#20049 subtracting PeriodIndex should raise TypeError tdi = TimedeltaIndex(['1 hours', '2 hours'], freq=tdi_freq) dti = Timestamp('2018-03-07 17:16:40') + tdi pi = dti.to_period(pi_freq) # TODO: parametrize over box for pi? tdi = tm.box_expected(tdi, box) with pytest.raises(TypeError): tdi - pi
def ordinal(v: pd.Timestamp, freq: str) -> int: return v.to_period(freq).ordinal
def test_to_period(self, dt64, ts): alt = Timestamp(dt64) assert ts.to_period("D") == alt.to_period("D")