- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 19.2k
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
Changes from 3 commits
85a72d7
              4be5326
              14b09c6
              a2af610
              98f3e11
              e7bc381
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -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`) | ||
|  | ||
| Numeric | ||
| ^^^^^^^ | ||
|  | @@ -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`) | ||
|          | ||
|  | ||
| Missing | ||
| ^^^^^^^ | ||
|  | @@ -1111,7 +1112,7 @@ Plotting | |
| - Bug in an error message in :meth:`DataFrame.plot`. Improved the error message if non-numerics are passed to :meth:`DataFrame.plot` (:issue:`25481`) | ||
| - Bug in incorrect ticklabel positions when plotting an index that are non-numeric / non-datetime (:issue:`7612`, :issue:`15912`, :issue:`22334`) | ||
| - Fixed bug causing plots of :class:`PeriodIndex` timeseries to fail if the frequency is a multiple of the frequency rule code (:issue:`14763`) | ||
| - | ||
| - Fixed bug when plotting a :class:`DatetimeIndex` with ``datetime.timezone.utc`` timezone (:issue:`17173`) | ||
| - | ||
| - | ||
|  | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -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): | ||
|          | ||
| # The cython indexing routines do not support ExtensionArrays. | ||
| # Defer to the next setting routine. | ||
| raise KeyError | ||
|          | ||
| self.index._engine.set_value(values, key, value) | ||
| return | ||
| except KeyError: | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -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(): | ||
|          | ||
| # GH 20441 | ||
| arr = pd.date_range("2017", periods=4, tz="US/Eastern") | ||
| index = [(0, 1), (0, 2), (0, 3), (0, 4)] | ||
| result = Series(arr, index=index) | ||
| expected = result.copy() | ||
| result[(0, 1)] = np.nan | ||
| expected.iloc[0] = np.nan | ||
| assert_series_equal(result, expected) | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -10,7 +10,7 @@ | |
|  | ||
| from pandas._libs.tslibs import conversion, timezones | ||
|  | ||
| from pandas import DatetimeIndex, Index, NaT, Series, Timestamp | ||
| from pandas import DatetimeIndex, Index, NaT, Series, Timestamp, to_datetime | ||
| from pandas.core.indexes.datetimes import date_range | ||
| import pandas.util.testing as tm | ||
|  | ||
|  | @@ -379,3 +379,11 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture): | |
| result = Series([Timestamp("2019", tz=tz)], dtype="datetime64[ns]") | ||
| expected = Series([Timestamp("2019")]) | ||
| tm.assert_series_equal(result, expected) | ||
|  | ||
| def test_numpy_reduction_with_tz_aware_dtype(self, tz_aware_fixture): | ||
| # GH 15552 | ||
| tz = tz_aware_fixture | ||
| 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.
Just FYI, we have NumPy in our inter-sphinx config so :meth:`numpy.minimum` would work.