Skip to content

AmbigousTimeError on Timestamp.floor during dst change #23521

Closed
@Safrone

Description

@Safrone

Code Sample, a copy-pastable example if possible

import pandas as pd
pd.Timestamp('2018-11-04 01:55:17.869342-0500', tz='America/New_York').floor('T')
Traceback (most recent call last):
  File "/venv/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 3265, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-42bf9ce66d1d>", line 1, in <module>
    pd.Timestamp('2018-11-04 01:55:17.869342-0500', tz='America/New_York').floor('T')
  File "pandas/_libs/tslibs/timestamps.pyx", line 696, in pandas._libs.tslibs.timestamps.Timestamp.floor
  File "pandas/_libs/tslibs/timestamps.pyx", line 667, in pandas._libs.tslibs.timestamps.Timestamp._round
  File "pandas/_libs/tslibs/timestamps.pyx", line 903, in pandas._libs.tslibs.timestamps.Timestamp.tz_localize
  File "pandas/_libs/tslibs/conversion.pyx", line 963, in pandas._libs.tslibs.conversion.tz_localize_to_utc
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from '2018-11-04 01:55:00', try using the 'ambiguous' argument

Problem description

AmbiguousTimeError thrown on floor of timestamp that leads to time within dst change.

Similar issues happen on ceil and round:

pd.Timestamp('2018-11-04 01:55:17.869342-0500', tz='America/New_York').ceil('T')
pd.Timestamp('2018-11-04 01:55:17.869342-0500', tz='America/New_York').round('T')

Expected Output

Timestamp('2018-11-04 01:55:00-0500', tz='America/New_York')

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-38-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.4
pytest: None
pip: 10.0.1
setuptools: 39.1.0
Cython: None
numpy: 1.15.2
scipy: None
pyarrow: None
xarray: None
IPython: 7.0.1
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions