Skip to content
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

AmbiguousTimeError in floor() operation #18946

tapia opened this issue Dec 26, 2017 · 1 comment


None yet
2 participants
Copy link

commented Dec 26, 2017

This is probably related to #18885

Given a DataFrame with a DST change on it:

df1=pd.DataFrame([pd.to_datetime('2017-10-29 02:00:00+02:00'),
                  pd.to_datetime('2017-10-29 02:00:00+01:00'),
                  pd.to_datetime('2017-10-29 03:00:00+01:00')],columns=['date'])
df1['date'] = df1['date'].dt.tz_localize('UTC').dt.tz_convert('Europe/Madrid')
df1['value'] = 1

When we try to do a floor() or ceil() operation, we get an AmbiguousTimeError exception:'H')

Expected output

0   2017-10-29 02:00:00+02:00
1   2017-10-29 02:00:00+01:00
2   2017-10-29 03:00:00+01:00

Actual output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/", line 115, in f
    return self._delegate_method(name, *args, **kwargs)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/", line 131, in _delegate_method
    result = method(*args, **kwargs)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/", line 118, in floor
    return self._round(freq, np.floor)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/", line 110, in _round
    self._shallow_copy(result, **attribs))
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/", line 230, in _ensure_localized
    result = result.tz_localize(
  File "(...)/venv/lib/python3.6/site-packages/pandas/util/", line 118, in wrapper
    return func(*args, **kwargs)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/", line 1858, in tz_localize
  File "pandas/_libs/tslib.pyx", line 3593, in pandas._libs.tslib.tz_localize_to_utc
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from Timestamp('2017-10-29 02:00:00'), try using the 'ambiguous' argument

This comment has been minimized.

Copy link

commented Dec 26, 2017

yes there a number of issues related to this. the fix is all the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.