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

Closed
tapia opened this issue Dec 26, 2017 · 1 comment · Fixed by #22647
Closed

AmbiguousTimeError in floor() operation #18946

tapia opened this issue Dec 26, 2017 · 1 comment · Fixed by #22647
Labels
Bug Timezones Timezone data dtype
Milestone

Comments

@tapia
Copy link

tapia 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:

df1.date.dt.floor('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/accessor.py", line 115, in f
    return self._delegate_method(name, *args, **kwargs)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/accessors.py", line 131, in _delegate_method
    result = method(*args, **kwargs)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/datetimelike.py", line 118, in floor
    return self._round(freq, np.floor)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/datetimelike.py", line 110, in _round
    self._shallow_copy(result, **attribs))
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/datetimelike.py", line 230, in _ensure_localized
    result = result.tz_localize(self.tz)
  File "(...)/venv/lib/python3.6/site-packages/pandas/util/_decorators.py", line 118, in wrapper
    return func(*args, **kwargs)
  File "(...)/venv/lib/python3.6/site-packages/pandas/core/indexes/datetimes.py", line 1858, in tz_localize
    errors=errors)
  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
@jreback
Copy link
Contributor

jreback 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
Labels
Bug Timezones Timezone data dtype
Projects
None yet
2 participants