11
11
import pandas .compat as compat
12
12
from pandas .core .dtypes .common import (
13
13
is_object_dtype , is_datetime64_dtype , is_datetime64tz_dtype ,
14
- needs_i8_conversion )
14
+ needs_i8_conversion , is_timedelta64_dtype )
15
15
import pandas .util .testing as tm
16
16
from pandas import (Series , Index , DatetimeIndex , TimedeltaIndex ,
17
17
PeriodIndex , Timedelta , IntervalIndex , Interval ,
18
18
CategoricalIndex , Timestamp , DataFrame , Panel )
19
+ from pandas .core .arrays import (
20
+ DatetimeArrayMixin as DatetimeArray ,
21
+ TimedeltaArrayMixin as TimedeltaArray ,
22
+ )
19
23
from pandas .compat import StringIO , PYPY , long
20
24
from pandas .compat .numpy import np_array_datetime64_compat
21
25
from pandas .core .arrays import PandasArray
@@ -383,8 +387,12 @@ def test_value_counts_unique_nunique(self):
383
387
assert result [0 ] == orig [0 ]
384
388
for r in result :
385
389
assert isinstance (r , Timestamp )
386
- tm .assert_numpy_array_equal (result ,
387
- orig ._values .astype (object ).values )
390
+
391
+ # TODO(#24024) once orig._values returns DTA, remove
392
+ # the `._eadata` below
393
+ tm .assert_numpy_array_equal (
394
+ result .astype (object ),
395
+ orig ._values ._eadata .astype (object ))
388
396
else :
389
397
tm .assert_numpy_array_equal (result , orig .values )
390
398
@@ -410,7 +418,9 @@ def test_value_counts_unique_nunique_null(self):
410
418
else :
411
419
o = o .copy ()
412
420
o [0 :2 ] = iNaT
413
- values = o ._values
421
+ # TODO(#24024) once Series._values returns DTA, remove
422
+ # the `._eadata` here
423
+ values = o ._values ._eadata
414
424
415
425
elif needs_i8_conversion (o ):
416
426
values [0 :2 ] = iNaT
@@ -431,7 +441,7 @@ def test_value_counts_unique_nunique_null(self):
431
441
o = klass (values .repeat (range (1 , len (o ) + 1 )))
432
442
o .name = 'a'
433
443
else :
434
- if is_datetime64tz_dtype ( o ):
444
+ if isinstance ( o , DatetimeIndex ):
435
445
expected_index = orig ._values ._shallow_copy (values )
436
446
else :
437
447
expected_index = Index (values )
@@ -472,8 +482,7 @@ def test_value_counts_unique_nunique_null(self):
472
482
Index (values [1 :], name = 'a' ))
473
483
elif is_datetime64tz_dtype (o ):
474
484
# unable to compare NaT / nan
475
- vals = values [2 :].astype (object ).values
476
- tm .assert_numpy_array_equal (result [1 :], vals )
485
+ tm .assert_extension_array_equal (result [1 :], values [2 :])
477
486
assert result [0 ] is pd .NaT
478
487
else :
479
488
tm .assert_numpy_array_equal (result [1 :], values [2 :])
@@ -1187,7 +1196,6 @@ def test_ndarray_values(array, expected):
1187
1196
1188
1197
@pytest .mark .parametrize ("arr" , [
1189
1198
np .array ([1 , 2 , 3 ]),
1190
- np .array ([1 , 2 , 3 ], dtype = "datetime64[ns]" ),
1191
1199
])
1192
1200
def test_numpy_array (arr ):
1193
1201
ser = pd .Series (arr )
@@ -1199,7 +1207,12 @@ def test_numpy_array(arr):
1199
1207
def test_numpy_array_all_dtypes (any_numpy_dtype ):
1200
1208
ser = pd .Series (dtype = any_numpy_dtype )
1201
1209
result = ser .array
1202
- assert isinstance (result , PandasArray )
1210
+ if is_datetime64_dtype (any_numpy_dtype ):
1211
+ assert isinstance (result , DatetimeArray )
1212
+ elif is_timedelta64_dtype (any_numpy_dtype ):
1213
+ assert isinstance (result , TimedeltaArray )
1214
+ else :
1215
+ assert isinstance (result , PandasArray )
1203
1216
1204
1217
1205
1218
@pytest .mark .parametrize ("array, attr" , [
0 commit comments