-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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 using drop on DatetimeIndex with DST change #18031
Comments
@JrtPec : Thanks for reporting this! This indeed does look a little strange. Feel free to investigate and put up a PR for this. For reference, do you mind posting the entire stacktrace? |
we don't have the as a work-around
|
pull requests welcome! |
Full traceback: AmbiguousTimeError Traceback (most recent call last)
<ipython-input-19-7d5e95692da7> in <module>()
----> 1 index.drop(index[0])
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexes/base.py in drop(self, labels, errors)
3741 labels[mask])
3742 indexer = indexer[~mask]
-> 3743 return self.delete(indexer)
3744
3745 @Appender(base._shared_docs['unique'] % _index_doc_kwargs)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexes/datetimes.py in delete(self, loc)
1773 if self.tz is not None:
1774 new_dates = libts.tz_convert(new_dates, 'UTC', self.tz)
-> 1775 return DatetimeIndex(new_dates, name=self.name, freq=freq, tz=self.tz)
1776
1777 def tz_convert(self, tz):
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
116 else:
117 kwargs[new_arg_name] = new_arg_value
--> 118 return func(*args, **kwargs)
119 return wrapper
120 return _deprecate_kwarg
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexes/datetimes.py in __new__(cls, data, freq, start, end, periods, copy, name, tz, verify_integrity, normalize, closed, ambiguous, dtype, **kwargs)
388 ints = subarr.view('i8')
389 subarr = libts.tz_localize_to_utc(ints, tz,
--> 390 ambiguous=ambiguous)
391 subarr = subarr.view(_NS_DTYPE)
392
pandas/_libs/tslib.pyx in pandas._libs.tslib.tz_localize_to_utc()
AmbiguousTimeError: Cannot infer dst time from Timestamp('2017-10-29 02:00:00'), try using the 'ambiguous' argument |
Hy, |
This looks fixed on master if anyone wants to put up a test:
|
Code Sample, a copy-pastable example if possible
Problem description
When dropping from a localized DateTimeIndex, behind the scenes the index is converted to UTC, the drop is performed, and then it is converted back to the original timezone. (This is what I make of the traceback).
This second conversion is ambiguous because the original index contains a DST change.
Expected Output
Output of
index.drop(index[0])
The text was updated successfully, but these errors were encountered: