diff --git a/doc/source/whatsnew/v0.16.1.txt b/doc/source/whatsnew/v0.16.1.txt index d0ffe37e20ddf..b15c39ae79b50 100755 --- a/doc/source/whatsnew/v0.16.1.txt +++ b/doc/source/whatsnew/v0.16.1.txt @@ -68,6 +68,7 @@ Enhancements - Allow ``Categorical.add_categories`` to accept ``Series`` or ``np.array``. (:issue:`9927`) - Add/delete ``str/dt/cat`` accessors dynamically from ``__dir__``. (:issue:`9910`) +- Add ``normalize`` as a ``dt`` accessor method. - ``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 ` diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index aa95986be0722..f4880fdbb5de4 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -83,7 +83,7 @@ def test_dt_namespace_accessor(self): ok_for_period = ok_for_base + ['qyear'] ok_for_dt = ok_for_base + ['date','time','microsecond','nanosecond', 'is_month_start', 'is_month_end', 'is_quarter_start', 'is_quarter_end', 'is_year_start', 'is_year_end', 'tz'] - ok_for_dt_methods = ['to_period','to_pydatetime','tz_localize','tz_convert'] + ok_for_dt_methods = ['to_period','to_pydatetime','tz_localize','tz_convert', 'normalize'] ok_for_td = ['days','seconds','microseconds','nanoseconds'] ok_for_td_methods = ['components','to_pytimedelta'] @@ -165,6 +165,7 @@ def compare(s, name): tm.assert_series_equal(s.dt.year,Series(np.array([2014,2014,2014],dtype='int64'),index=index)) tm.assert_series_equal(s.dt.month,Series(np.array([2,2,2],dtype='int64'),index=index)) tm.assert_series_equal(s.dt.second,Series(np.array([0,1,2],dtype='int64'),index=index)) + tm.assert_series_equal(s.dt.normalize(), pd.Series([s[0]] * 3, index=index)) # periodindex for s in [Series(period_range('20130101',periods=5,freq='D'))]: diff --git a/pandas/tseries/common.py b/pandas/tseries/common.py index 2ceece087387e..8e468a7701462 100644 --- a/pandas/tseries/common.py +++ b/pandas/tseries/common.py @@ -125,7 +125,7 @@ def to_pydatetime(self): accessors=DatetimeIndex._datetimelike_ops, typ='property') DatetimeProperties._add_delegate_accessors(delegate=DatetimeIndex, - accessors=["to_period","tz_localize","tz_convert"], + accessors=["to_period","tz_localize","tz_convert","normalize"], typ='method') class TimedeltaProperties(Properties):