Skip to content

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

Merged
merged 6 commits into from
Jul 17, 2019

Conversation

mroeschke
Copy link
Member

1 timezone plotting bug, 1 indexing bug with tz data, 1 timezone data regression test

@mroeschke mroeschke added Bug Visualization plotting Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype labels Jul 12, 2019
arg = to_datetime(["2019"]).tz_localize(tz)
expected = Series(arg)
result = np.minimum(expected, expected)
tm.assert_series_equal(result, expected)
Copy link
Member

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

if is_extension_array_dtype(values):
# The cython indexing routines do not support ExtensionArrays.
# Defer to the next setting routine.
raise KeyError
Copy link
Member

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

@mroeschke mroeschke added this to the 0.25.0 milestone Jul 13, 2019
@@ -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):
Copy link
Contributor

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):
Copy link
Contributor

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;

Copy link
Contributor

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():
Copy link
Contributor

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)

@@ -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`)
Copy link
Contributor

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.

@@ -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`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a -> an

@@ -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):
Copy link
Contributor

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)?

Copy link
Member Author

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):
Copy link
Contributor

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?

@jreback jreback merged commit 0d2ec3e into pandas-dev:master Jul 17, 2019
@jreback
Copy link
Contributor

jreback commented Jul 17, 2019

thanks @mroeschke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype Visualization plotting
Projects
None yet
4 participants