New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimeIndex.__iter__().next() rounds time to microseconds, when timezone aware #19603

enritoomey opened this Issue Feb 8, 2018 · 1 comment


None yet
3 participants

enritoomey commented Feb 8, 2018

Code Sample

>> import pandas as pd
>> datetimeindex = pd.DatetimeIndex(["2018-02-08 15:00:00.168456358"])
>> datetimeindex
DatetimeIndex(['2018-02-08 15:00:00.168456358'], dtype='datetime64[ns]', freq=None)
>> datetimeindex = datetimeindex.tz_localize(datetime.timezone.utc)
>> datetimeindex
DatetimeIndex(['2018-02-08 15:00:00.168456358+00:00'], dtype='datetime64[ns, UTC+00:00]', freq=None)
>> datetimeindex.__getitem__(0)
Timestamp('2018-02-08 15:00:00.168456358+0000', tz='UTC+00:00')
>> datetimeindex.__iter__().__next__()
Timestamp('2018-02-08 15:00:00.168456+0000', tz='UTC+00:00')

Problem description

When using localize DateTimeIndex with nanosecond precision, getitem behavious differs from iter().next behaviour, as when iterating thought the DateTimeIndex the date is round to microseconds. This doen not happends if the DatetimeIndex has no timezone.

Output of pd.show_versions()


commit: None
python-bits: 64
OS: Linux
OS-release: 4.9.0-0.bpo.2-amd64
machine: x86_64
byteorder: little
LC_ALL: None

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 36.5.0
Cython: None
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None


This comment has been minimized.


TomAugspurger commented Feb 9, 2018

It seems like this is just for UTC?

In [81]: list(datetimeindex)[0] == datetimeindex[0]
Out[81]: False

In [82]: list(datetimeindex.tz_convert("US/Central"))[0] == datetimeindex.tz_convert("US/Central")[0]
Out[82]: True

You're welcome to take a look @enritoomey! Presumably in ints_to_pydatetime in pandas/_libs/tslib.pyx

@TomAugspurger TomAugspurger added this to the Next Major Release milestone Feb 9, 2018

@jreback jreback modified the milestones: Next Major Release, 0.23.0 Feb 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment