Skip to content

Commit 7484eb3

Browse files
TomAugspurgerKevin D Smith
authored and
Kevin D Smith
committed
Call finalize in Series.dt (pandas-dev#36554)
xref pandas-dev#28283
1 parent 6d5deab commit 7484eb3

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ Other
374374
^^^^^
375375
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` incorrectly raising ``AssertionError`` instead of ``ValueError`` when invalid parameter combinations are passed (:issue:`36045`)
376376
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` with numeric values and string ``to_replace`` (:issue:`34789`)
377+
- Fixed metadata propagation in the :class:`Series.dt` accessor (:issue:`28283`)
377378
- Bug in :meth:`Series.transform` would give incorrect results or raise when the argument ``func`` was dictionary (:issue:`35811`)
378379
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`)
379380

pandas/core/indexes/accessors.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _delegate_property_get(self, name):
7878
else:
7979
index = self._parent.index
8080
# return the result as a Series, which is by definition a copy
81-
result = Series(result, index=index, name=self.name)
81+
result = Series(result, index=index, name=self.name).__finalize__(self._parent)
8282

8383
# setting this object will show a SettingWithCopyWarning/Error
8484
result._is_copy = (
@@ -106,7 +106,9 @@ def _delegate_method(self, name, *args, **kwargs):
106106
if not is_list_like(result):
107107
return result
108108

109-
result = Series(result, index=self._parent.index, name=self.name)
109+
result = Series(result, index=self._parent.index, name=self.name).__finalize__(
110+
self._parent
111+
)
110112

111113
# setting this object will show a SettingWithCopyWarning/Error
112114
result._is_copy = (
@@ -371,7 +373,11 @@ def components(self):
371373
3 0 0 0 3 0 0 0
372374
4 0 0 0 4 0 0 0
373375
"""
374-
return self._get_values().components.set_index(self._parent.index)
376+
return (
377+
self._get_values()
378+
.components.set_index(self._parent.index)
379+
.__finalize__(self._parent)
380+
)
375381

376382
@property
377383
def freq(self):

pandas/tests/generic/test_finalize.py

-4
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ def test_string_method(method):
678678
],
679679
ids=idfn,
680680
)
681-
@not_implemented_mark
682681
def test_datetime_method(method):
683682
s = pd.Series(pd.date_range("2000", periods=4))
684683
s.attrs = {"a": 1}
@@ -714,7 +713,6 @@ def test_datetime_method(method):
714713
"days_in_month",
715714
],
716715
)
717-
@not_implemented_mark
718716
def test_datetime_property(attr):
719717
s = pd.Series(pd.date_range("2000", periods=4))
720718
s.attrs = {"a": 1}
@@ -725,7 +723,6 @@ def test_datetime_property(attr):
725723
@pytest.mark.parametrize(
726724
"attr", ["days", "seconds", "microseconds", "nanoseconds", "components"]
727725
)
728-
@not_implemented_mark
729726
def test_timedelta_property(attr):
730727
s = pd.Series(pd.timedelta_range("2000", periods=4))
731728
s.attrs = {"a": 1}
@@ -734,7 +731,6 @@ def test_timedelta_property(attr):
734731

735732

736733
@pytest.mark.parametrize("method", [operator.methodcaller("total_seconds")])
737-
@not_implemented_mark
738734
def test_timedelta_methods(method):
739735
s = pd.Series(pd.timedelta_range("2000", periods=4))
740736
s.attrs = {"a": 1}

0 commit comments

Comments
 (0)