BUG: to_period behaves different between Timestamp and DatetimeIndex with timezones · Issue #22905 · pandas-dev/pandas (original) (raw)
After 935c5d1 pandas/tests/indexes/datetimes/test_astype.py
fails depending on the timezone:
in fact
TZ=Etc/GMT+1 pytest pandas/tests/indexes/datetimes/test_astype.py -k TestToPeriod
is OK while
TZ=Etc/GMT-1 pytest pandas/tests/indexes/datetimes/test_astype.py -k TestToPeriod
fails.
This can be nailed down to the following code sample.
Code Sample
ts = pd.date_range('1/1/2000', '2/1/2000', tz='Etc/GMT-1') ts.to_period()[0] == ts[0].to_period() False ts.to_period()[0], ts[0].to_period() (Period('1999-12-31', 'D'), Period('2000-01-01', 'D')) ts = pd.date_range('1/1/2000', '2/1/2000', tz='Etc/GMT+1') ts.to_period()[0] == ts[0].to_period() True ts.to_period()[0], ts[0].to_period() (Period('2000-01-01', 'D'), Period('2000-01-01', 'D'))
Problem description
It seems that ts.to_period()[0] == ts[0].to_period()
depends on tzinfo, true if west of GMT, false if east of GMT. Before 935c5d1 ts.to_period()[0] == ts[0].to_period()
is always True
irrespective of tzinfo.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: 935c5d1453938a284805cb7d3c0c3255390997a7 python: 3.7.0.final.0 python-bits: 64 OS: Darwin OS-release: 17.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8
pandas: 0.24.0.dev0+555.g935c5d145 pytest: 3.7.4 pip: 18.0 setuptools: 39.0.1 Cython: 0.28.5 numpy: 1.15.1 scipy: 1.1.0 pyarrow: None xarray: 0.10.9 IPython: 6.5.0 sphinx: 1.7.9 patsy: 0.5.0 dateutil: 2.7.3 pytz: 2018.5 blosc: 1.5.1 bottleneck: 1.2.1 tables: None numexpr: 2.6.8 feather: None matplotlib: 3.0.0 openpyxl: 2.5.5 xlrd: 1.1.0 xlwt: 1.3.0 xlsxwriter: 1.1.1 lxml: 4.2.5 bs4: 4.6.3 html5lib: 1.0.1 sqlalchemy: 1.2.12 pymysql: 0.9.2 psycopg2: None jinja2: 2.10 s3fs: 0.1.6 fastparquet: 0.1.6 pandas_gbq: None pandas_datareader: None gcsfs: 0.1.2