-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix timezone-related indexing and plotting bugs #27367
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
Conversation
arg = to_datetime(["2019"]).tz_localize(tz) | ||
expected = Series(arg) | ||
result = np.minimum(expected, expected) | ||
tm.assert_series_equal(result, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might belong in tests.reductions? Especially if it can be extended to the other box classes
pandas/core/series.py
Outdated
if is_extension_array_dtype(values): | ||
# The cython indexing routines do not support ExtensionArrays. | ||
# Defer to the next setting routine. | ||
raise KeyError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this go outside the try/except and instead of raising just copy line 1260? it's one-liner either way
pandas/core/series.py
Outdated
@@ -1250,6 +1250,10 @@ def setitem(key, value): | |||
def _set_with_engine(self, key, value): | |||
values = self._values | |||
try: | |||
if is_extension_array_dtype(values): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this outside of the try/except?
@@ -159,6 +159,14 @@ def test_same_tz_min_max_axis_1(self, op, expected_col): | |||
expected = df[expected_col].rename(None) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
def test_numpy_reduction_with_tz_aware_dtype(self, tz_aware_fixture): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you parametrize and test both np.minimum & np.maximum;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of that?
@@ -847,3 +847,14 @@ def test_head_tail(test_data): | |||
assert_series_equal(test_data.series.head(0), test_data.series[0:0]) | |||
assert_series_equal(test_data.series.tail(), test_data.series[-5:]) | |||
assert_series_equal(test_data.series.tail(0), test_data.series[0:0]) | |||
|
|||
|
|||
def test_setitem_tuple_with_datetimetz(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move to test_datetime (same dir)
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -995,6 +995,7 @@ Timezones | |||
- Bug in :func:`DataFrame.join` where joining a timezone aware index with a timezone aware column would result in a column of ``NaN`` (:issue:`26335`) | |||
- Bug in :func:`date_range` where ambiguous or nonexistent start or end times were not handled by the ``ambiguous`` or ``nonexistent`` keywords respectively (:issue:`27088`) | |||
- Bug in :meth:`DatetimeIndex.union` when combining a timezone aware and timezone unaware :class:`DatetimeIndex` (:issue:`21671`) | |||
- Bug when applying a numpy reduction function (e.g. ``np.minimum``) to a timezone aware :class:`Series` (:issue:`15552`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, we have NumPy in our inter-sphinx config so :meth:`numpy.minimum` would work.
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -1054,7 +1055,7 @@ Indexing | |||
- Bug in :class:`CategoricalIndex` and :class:`Categorical` incorrectly raising ``ValueError`` instead of ``TypeError`` when a list is passed using the ``in`` operator (``__contains__``) (:issue:`21729`) | |||
- Bug in setting a new value in a :class:`Series` with a :class:`Timedelta` object incorrectly casting the value to an integer (:issue:`22717`) | |||
- Bug in :class:`Series` setting a new key (``__setitem__``) with a timezone-aware datetime incorrectly raising ``ValueError`` (:issue:`12862`) | |||
- | |||
- Bug in :class:`Series` setting a existing tuple key (``__setitem__``) with timezone-aware datetime values incorrectly raising ``TypeError`` (:issue:`20441`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a -> an
pandas/core/series.py
Outdated
@@ -1250,6 +1250,10 @@ def setitem(key, value): | |||
def _set_with_engine(self, key, value): | |||
values = self._values | |||
try: | |||
if is_extension_array_dtype(values): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is values
an array-like or list-like? Can we do is_extension_array_dtype(values.dtype)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Changed to pass the dtype instead
@@ -159,6 +159,14 @@ def test_same_tz_min_max_axis_1(self, op, expected_col): | |||
expected = df[expected_col].rename(None) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
def test_numpy_reduction_with_tz_aware_dtype(self, tz_aware_fixture): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of that?
thanks @mroeschke |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
1 timezone plotting bug, 1 indexing bug with tz data, 1 timezone data regression test