@@ -193,6 +193,7 @@ def test_value_counts_bins(index_or_series):
193
193
194
194
def test_value_counts_datetime64 (index_or_series ):
195
195
klass = index_or_series
196
+ warn = None if klass is Index else FutureWarning
196
197
197
198
# GH 3002, datetime64[ns]
198
199
# don't test names though
@@ -223,12 +224,15 @@ def test_value_counts_datetime64(index_or_series):
223
224
["2010-01-01 00:00:00" , "2009-01-01 00:00:00" , "2008-09-09 00:00:00" ],
224
225
dtype = "datetime64[ns]" ,
225
226
)
227
+ with tm .assert_produces_warning (warn , match = "DatetimeArray" ):
228
+ unq = s .unique ()
226
229
if isinstance (s , Index ):
227
- tm .assert_index_equal (s . unique () , DatetimeIndex (expected ))
230
+ tm .assert_index_equal (unq , DatetimeIndex (expected ))
228
231
else :
229
- tm .assert_numpy_array_equal (s . unique () , expected )
232
+ tm .assert_numpy_array_equal (unq , expected )
230
233
231
- assert s .nunique () == 3
234
+ with tm .assert_produces_warning (warn , match = "DatetimeArray" ):
235
+ assert s .nunique () == 3
232
236
233
237
# with NaT
234
238
s = df ["dt" ].copy ()
@@ -243,7 +247,9 @@ def test_value_counts_datetime64(index_or_series):
243
247
tm .assert_series_equal (result , expected_s )
244
248
245
249
assert s .dtype == "datetime64[ns]"
246
- unique = s .unique ()
250
+ warn = None if isinstance (s , DatetimeIndex ) else FutureWarning
251
+ with tm .assert_produces_warning (warn , match = "DatetimeArray" ):
252
+ unique = s .unique ()
247
253
assert unique .dtype == "datetime64[ns]"
248
254
249
255
# numpy_array_equal cannot compare pd.NaT
@@ -254,8 +260,9 @@ def test_value_counts_datetime64(index_or_series):
254
260
tm .assert_numpy_array_equal (unique [:3 ], expected )
255
261
assert pd .isna (unique [3 ])
256
262
257
- assert s .nunique () == 3
258
- assert s .nunique (dropna = False ) == 4
263
+ with tm .assert_produces_warning (warn , match = "DatetimeArray" ):
264
+ assert s .nunique () == 3
265
+ assert s .nunique (dropna = False ) == 4
259
266
260
267
# timedelta64[ns]
261
268
td = df .dt - df .dt + timedelta (1 )
@@ -269,7 +276,9 @@ def test_value_counts_datetime64(index_or_series):
269
276
if isinstance (td , Index ):
270
277
tm .assert_index_equal (td .unique (), expected )
271
278
else :
272
- tm .assert_numpy_array_equal (td .unique (), expected .values )
279
+ with tm .assert_produces_warning (FutureWarning , match = "TimedeltaArray" ):
280
+ res = td .unique ()
281
+ tm .assert_numpy_array_equal (res , expected .values )
273
282
274
283
td2 = timedelta (1 ) + (df .dt - df .dt )
275
284
td2 = klass (td2 , name = "dt" )
0 commit comments