Skip to content

Resolving Index Resetting for tz_localize #43226

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 25 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/whatsnew/v1.3.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Fixed regressions

Bug fixes
~~~~~~~~~
- Bug in :meth:`.DataFrameGroupBy.agg` and :meth:`.DataFrameGroupBy.transform` with ``engine="numba"`` where ``index`` data was not being correctly passed into ``func`` (:issue:`43133`)
-
- Bug in :meth:`.DataFrameGroupBy.agg` and :meth:`.DataFrameGroupBy.transform` with engine="numba" where index data was not being correctly passed into func (:issue:`43133`)
Copy link
Member

Choose a reason for hiding this comment

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

Please revert the changes to this entry.

- Fixed bug in :func:`__new__` of :class:`CombinedDatetimelikeProperties` maintains index of Categorical Datetime series (:issue:`43080`)
Copy link
Member

Choose a reason for hiding this comment

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

  1. This note should go in v.1.4.0.rst
  2. The message should relate to a user facing API i.e. dt.tz_convert on a CategorialIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I will make the necessary changes ,
Just wanted to be clear , why it shouldn't be in v.1.3.3.rst ?

Copy link
Member

Choose a reason for hiding this comment

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

1.3.3 is typically for regressions or bugs for very recently added features


.. ---------------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def __new__(cls, data: Series):
name=orig.name,
copy=False,
dtype=orig._values.categories.dtype,
index=orig.index,
)

if is_datetime64_dtype(data.dtype):
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/series/methods/test_tz_localize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pandas._libs.tslibs import timezones

from pandas import (
CategoricalDtype,
DatetimeIndex,
NaT,
Series,
Expand Down Expand Up @@ -41,6 +42,23 @@ def test_series_tz_localize_ambiguous_bool(self):
result = ser.dt.tz_localize("US/Central", ambiguous=[False])
tm.assert_series_equal(result, expected1)

def test_series_tz_localize_matching_index(self):
# Matching the index of the result with that of the original series
# GH 43080
dt_series = Series(
date_range(start="2021-01-01T02:00:00", periods=5, freq="1D"),
index=[2, 6, 7, 8, 11],
)
cat_series = dt_series.astype(CategoricalDtype())
Copy link
Member

Choose a reason for hiding this comment

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

Can you construct without astype?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah , I have done that .

result = cat_series.dt.tz_localize("Europe/Berlin")
expected = Series(
date_range(
start="2021-01-01T02:00:00", periods=5, freq="1D", tz="Europe/Berlin"
),
index=[2, 6, 7, 8, 11],
)
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("tz", ["Europe/Warsaw", "dateutil/Europe/Warsaw"])
@pytest.mark.parametrize(
"method, exp",
Expand Down