@@ -84,17 +84,25 @@ def test_dt_namespace_accessor(self):
8484 # GH 7207
8585 # test .dt namespace accessor
8686
87- ok_for_base = ['year' ,'month' ,'day' ,'hour' ,'minute' ,'second' ,'weekofyear' ,'week' ,'dayofweek' ,'weekday' ,'dayofyear' ,'quarter' ,'freq' ,'days_in_month' ,'daysinmonth' ]
87+ ok_for_base = ['year' , 'month' , 'day' , 'hour' , 'minute' , 'second' ,
88+ 'weekofyear' , 'week' , 'dayofweek' , 'weekday' ,
89+ 'dayofyear' , 'quarter' , 'freq' , 'days_in_month' ,
90+ 'daysinmonth' ]
8891 ok_for_period = ok_for_base + ['qyear' ]
8992 ok_for_period_methods = ['strftime' ]
90- ok_for_dt = ok_for_base + ['date' ,'time' ,'microsecond' ,'nanosecond' , 'is_month_start' , 'is_month_end' , 'is_quarter_start' ,
91- 'is_quarter_end' , 'is_year_start' , 'is_year_end' , 'tz' ]
92- ok_for_dt_methods = ['to_period' ,'to_pydatetime' ,'tz_localize' ,'tz_convert' , 'normalize' , 'strftime' , 'round' , 'floor' , 'ceil' ]
93- ok_for_td = ['days' ,'seconds' ,'microseconds' ,'nanoseconds' ]
94- ok_for_td_methods = ['components' ,'to_pytimedelta' ,'total_seconds' ,'round' , 'floor' , 'ceil' ]
93+ ok_for_dt = ok_for_base + ['date' , 'time' , 'microsecond' , 'nanosecond' ,
94+ 'is_month_start' , 'is_month_end' ,
95+ 'is_quarter_start' , 'is_quarter_end' ,
96+ 'is_year_start' , 'is_year_end' , 'tz' ]
97+ ok_for_dt_methods = ['to_period' , 'to_pydatetime' , 'tz_localize' ,
98+ 'tz_convert' , 'normalize' , 'strftime' , 'round' ,
99+ 'floor' , 'ceil' ]
100+ ok_for_td = ['days' , 'seconds' , 'microseconds' , 'nanoseconds' ]
101+ ok_for_td_methods = ['components' , 'to_pytimedelta' , 'total_seconds' ,
102+ 'round' , 'floor' , 'ceil' ]
95103
96104 def get_expected (s , name ):
97- result = getattr (Index (s ._values ),prop )
105+ result = getattr (Index (s ._values ), prop )
98106 if isinstance (result , np .ndarray ):
99107 if com .is_integer_dtype (result ):
100108 result = result .astype ('int64' )
@@ -141,26 +149,42 @@ def compare(s, name):
141149 tm .assert_series_equal (result , expected )
142150
143151 # round
144- s = Series (pd .to_datetime (['2012-01-01 13:00:00' , '2012-01-01 12:01:00' , '2012-01-01 08:00:00' ]))
152+ s = Series (pd .to_datetime (['2012-01-01 13:00:00' ,
153+ '2012-01-01 12:01:00' ,
154+ '2012-01-01 08:00:00' ]))
145155 result = s .dt .round ('D' )
146- expected = Series (pd .to_datetime (['2012-01-02' , '2012-01-02' , '2012-01-01' ]))
156+ expected = Series (pd .to_datetime (['2012-01-02' ,
157+ '2012-01-02' ,
158+ '2012-01-01' ]))
147159 tm .assert_series_equal (result , expected )
148160
149161 # round with tz
150- result = s .dt .tz_localize ('UTC' ).dt .tz_convert ('US/Eastern' ).dt .round ('D' )
151- expected = Series (pd .to_datetime (['2012-01-01' , '2012-01-01' , '2012-01-01' ]).tz_localize ('US/Eastern' ))
162+ result = s .dt .tz_localize ('UTC' ).dt .tz_convert (
163+ 'US/Eastern' ).dt .round ('D' )
164+ expected = Series (pd .to_datetime (['2012-01-01' ,
165+ '2012-01-01' ,
166+ '2012-01-01' ]
167+ ).tz_localize ('US/Eastern' ))
152168 tm .assert_series_equal (result , expected )
153169
154170 # floor
155- s = Series (pd .to_datetime (['2012-01-01 13:00:00' , '2012-01-01 12:01:00' , '2012-01-01 08:00:00' ]))
171+ s = Series (pd .to_datetime (['2012-01-01 13:00:00' ,
172+ '2012-01-01 12:01:00' ,
173+ '2012-01-01 08:00:00' ]))
156174 result = s .dt .floor ('D' )
157- expected = Series (pd .to_datetime (['2012-01-01' , '2012-01-01' , '2012-01-01' ]))
175+ expected = Series (pd .to_datetime (['2012-01-01' ,
176+ '2012-01-01' ,
177+ '2012-01-01' ]))
158178 tm .assert_series_equal (result , expected )
159179
160180 # ceil
161- s = Series (pd .to_datetime (['2012-01-01 13:00:00' , '2012-01-01 12:01:00' , '2012-01-01 08:00:00' ]))
181+ s = Series (pd .to_datetime (['2012-01-01 13:00:00' ,
182+ '2012-01-01 12:01:00' ,
183+ '2012-01-01 08:00:00' ]))
162184 result = s .dt .ceil ('D' )
163- expected = Series (pd .to_datetime (['2012-01-02' , '2012-01-02' , '2012-01-02' ]))
185+ expected = Series (pd .to_datetime (['2012-01-02' ,
186+ '2012-01-02' ,
187+ '2012-01-02' ]))
164188 tm .assert_series_equal (result , expected )
165189
166190 # datetimeindex with tz
0 commit comments