Skip to content

Commit 7f43252

Browse files
haydjreback
authored andcommitted
ENH Add normalize method to Series dt accessor.
1 parent a4a1d12 commit 7f43252

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

doc/source/whatsnew/v0.16.1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Enhancements
6868
- Allow ``Categorical.add_categories`` to accept ``Series`` or ``np.array``. (:issue:`9927`)
6969

7070
- Add/delete ``str/dt/cat`` accessors dynamically from ``__dir__``. (:issue:`9910`)
71+
- Add ``normalize`` as a ``dt`` accessor method.
7172

7273
- ``DataFrame`` and ``Series`` now have ``_constructor_expanddim`` property as overridable constructor for one higher dimensionality data. This should be used only when it is really needed, see :ref:`here <ref-subclassing-pandas>`
7374

pandas/tests/test_series.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_dt_namespace_accessor(self):
8383
ok_for_period = ok_for_base + ['qyear']
8484
ok_for_dt = ok_for_base + ['date','time','microsecond','nanosecond', 'is_month_start', 'is_month_end', 'is_quarter_start',
8585
'is_quarter_end', 'is_year_start', 'is_year_end', 'tz']
86-
ok_for_dt_methods = ['to_period','to_pydatetime','tz_localize','tz_convert']
86+
ok_for_dt_methods = ['to_period','to_pydatetime','tz_localize','tz_convert', 'normalize']
8787
ok_for_td = ['days','seconds','microseconds','nanoseconds']
8888
ok_for_td_methods = ['components','to_pytimedelta']
8989

@@ -165,6 +165,7 @@ def compare(s, name):
165165
tm.assert_series_equal(s.dt.year,Series(np.array([2014,2014,2014],dtype='int64'),index=index))
166166
tm.assert_series_equal(s.dt.month,Series(np.array([2,2,2],dtype='int64'),index=index))
167167
tm.assert_series_equal(s.dt.second,Series(np.array([0,1,2],dtype='int64'),index=index))
168+
tm.assert_series_equal(s.dt.normalize(), pd.Series([s[0]] * 3, index=index))
168169

169170
# periodindex
170171
for s in [Series(period_range('20130101',periods=5,freq='D'))]:

pandas/tseries/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def to_pydatetime(self):
125125
accessors=DatetimeIndex._datetimelike_ops,
126126
typ='property')
127127
DatetimeProperties._add_delegate_accessors(delegate=DatetimeIndex,
128-
accessors=["to_period","tz_localize","tz_convert"],
128+
accessors=["to_period","tz_localize","tz_convert","normalize"],
129129
typ='method')
130130

131131
class TimedeltaProperties(Properties):

0 commit comments

Comments
 (0)