23
23
pandas_release = packaging .version .parse (pd .__version__ ).release
24
24
25
25
SAMPLE_RAW_VALUES = dict (
26
- dbdate = (datetime .date (2021 , 2 , 2 ), "2021-2-3" , None ),
27
- dbtime = (datetime .time (1 , 2 , 2 ), "1:2:3.5" , None ),
26
+ dbdate = (datetime .date (2021 , 2 , 2 ), "2021-2-3" , pd . NaT ),
27
+ dbtime = (datetime .time (1 , 2 , 2 ), "1:2:3.5" , pd . NaT ),
28
28
)
29
29
SAMPLE_VALUES = dict (
30
30
dbdate = (
@@ -90,19 +90,19 @@ def test_array_construction(dtype, factory_method):
90
90
factory = getattr (factory , factory_method )
91
91
if factory_method == "_from_sequence_of_strings" :
92
92
sample_raw_values = [
93
- str (v ) if v is not None else v for v in sample_raw_values
93
+ str (v ) if not pd . isna ( v ) else v for v in sample_raw_values
94
94
]
95
95
a = factory (sample_raw_values )
96
96
assert len (a ) == 3
97
97
assert a .size == 3
98
98
assert a .shape == (3 ,)
99
99
sample_values = SAMPLE_VALUES [dtype ]
100
100
assert a [0 ], a [1 ] == sample_values [:2 ]
101
- assert a [2 ] is None
101
+ assert pd . isna ( a [2 ]) and a [ 2 ] is pd . NaT
102
102
103
103
# implementation details:
104
104
assert a .nbytes == 24
105
- assert np .array_equal (
105
+ np .testing . assert_array_equal (
106
106
a ._ndarray
107
107
== np .array (SAMPLE_DT_VALUES [dtype ][:2 ] + ("NaT" ,), dtype = "datetime64[us]" ),
108
108
[True , True , False ],
@@ -121,7 +121,7 @@ def test_time_series_construction(dtype):
121
121
s = pd .Series (SAMPLE_RAW_VALUES [dtype ], dtype = dtype )
122
122
assert len (s ) == 3
123
123
assert s [0 ], s [1 ] == sample_values [:2 ]
124
- assert s [2 ] is None
124
+ assert s [2 ] is pd . NaT
125
125
assert s .nbytes == 24
126
126
assert isinstance (s .array , _cls (dtype ))
127
127
@@ -166,8 +166,8 @@ def test_timearray_comparisons(
166
166
# Note that the right_obs comparisons work because
167
167
# they're called on right_obs rather then left, because
168
168
# TimeArrays only support comparisons with TimeArrays.
169
- assert np .array_equal (comparisons [op ](left , r ), expected )
170
- assert np .array_equal (complements [op ](left , r ), ~ expected )
169
+ np .testing . assert_array_equal (comparisons [op ](left , r ), expected )
170
+ np .testing . assert_array_equal (complements [op ](left , r ), ~ expected )
171
171
172
172
# Bad shape
173
173
for bad_shape in ([], [1 , 2 , 3 ]):
@@ -186,10 +186,10 @@ def test_timearray_comparisons(
186
186
[1 ], # a single-element array gets broadcast
187
187
):
188
188
if op == "==" :
189
- assert np .array_equal (
189
+ np .testing . assert_array_equal (
190
190
comparisons [op ](left , np .array (bad_items )), np .array ([False , False ])
191
191
)
192
- assert np .array_equal (
192
+ np .testing . assert_array_equal (
193
193
complements [op ](left , np .array (bad_items )), np .array ([True , True ])
194
194
)
195
195
else :
@@ -204,7 +204,7 @@ def test_timearray_comparisons(
204
204
def test___getitem___arrayindex (dtype ):
205
205
cls = _cls (dtype )
206
206
sample_values = SAMPLE_VALUES [dtype ]
207
- assert np .array_equal (
207
+ np .testing . assert_array_equal (
208
208
cls (sample_values )[[1 , 3 ]], cls ([sample_values [1 ], sample_values [3 ]]),
209
209
)
210
210
@@ -215,21 +215,23 @@ def test_timearray_slicing(dtype):
215
215
b = a [:]
216
216
assert b is not a
217
217
assert b .__class__ == a .__class__
218
- assert np .array_equal ( b , a )
218
+ np .testing . assert_array_equal ( b . _ndarray , a . _ndarray )
219
219
220
220
sample_values = SAMPLE_VALUES [dtype ]
221
221
cls = _cls (dtype )
222
- assert np .array_equal (a [:1 ], cls ._from_sequence (sample_values [:1 ]))
222
+ np .testing .assert_array_equal (
223
+ a [:1 ]._ndarray , cls ._from_sequence (sample_values [:1 ])._ndarray
224
+ )
223
225
224
226
# Assignment works:
225
227
a [:1 ] = cls ._from_sequence ([sample_values [2 ]])
226
- assert np .array_equal (
228
+ np .testing . assert_array_equal (
227
229
a [:2 ], cls ._from_sequence ([sample_values [2 ], sample_values [1 ]])
228
230
)
229
231
230
232
# Series also work:
231
233
s = pd .Series (SAMPLE_RAW_VALUES [dtype ], dtype = dtype )
232
- assert np .array_equal (s [:1 ].array , cls ._from_sequence ([sample_values [0 ]]))
234
+ np .testing . assert_array_equal (s [:1 ].array , cls ._from_sequence ([sample_values [0 ]]))
233
235
234
236
235
237
@for_date_and_time
@@ -238,9 +240,13 @@ def test_item_assignment(dtype):
238
240
sample_values = SAMPLE_VALUES [dtype ]
239
241
cls = _cls (dtype )
240
242
a [0 ] = sample_values [2 ]
241
- assert np .array_equal (a , cls ._from_sequence ([sample_values [2 ], sample_values [1 ]]))
243
+ np .testing .assert_array_equal (
244
+ a , cls ._from_sequence ([sample_values [2 ], sample_values [1 ]])
245
+ )
242
246
a [1 ] = None
243
- assert np .array_equal (a , cls ._from_sequence ([sample_values [2 ], None ]))
247
+ np .testing .assert_array_equal (
248
+ a ._ndarray , cls ._from_sequence ([sample_values [2 ], None ])._ndarray
249
+ )
244
250
245
251
246
252
@for_date_and_time
@@ -249,9 +255,9 @@ def test_array_assignment(dtype):
249
255
cls = _cls (dtype )
250
256
sample_values = SAMPLE_VALUES [dtype ]
251
257
a [a .isna ()] = sample_values [3 ]
252
- assert np .array_equal (a , cls ([sample_values [i ] for i in (0 , 1 , 3 )]))
258
+ np .testing . assert_array_equal (a , cls ([sample_values [i ] for i in (0 , 1 , 3 )]))
253
259
a [[0 , 2 ]] = sample_values [2 ]
254
- assert np .array_equal (a , cls ([sample_values [i ] for i in (2 , 1 , 2 )]))
260
+ np .testing . assert_array_equal (a , cls ([sample_values [i ] for i in (2 , 1 , 2 )]))
255
261
256
262
257
263
@for_date_and_time
@@ -270,7 +276,7 @@ def test_copy(dtype):
270
276
b = a .copy ()
271
277
assert b is not a
272
278
assert b ._ndarray is not a ._ndarray
273
- assert np .array_equal (b , a )
279
+ np .testing . assert_array_equal (b , a )
274
280
275
281
276
282
@for_date_and_time
@@ -280,7 +286,7 @@ def test_from_ndarray_copy(dtype):
280
286
a = cls ._from_sequence (sample_values )
281
287
b = cls (a ._ndarray , copy = True )
282
288
assert b ._ndarray is not a ._ndarray
283
- assert np .array_equal (b , a )
289
+ np .testing . assert_array_equal (b , a )
284
290
285
291
286
292
@for_date_and_time
@@ -310,7 +316,7 @@ def test__validate_scalar_invalid(dtype):
310
316
[
311
317
(False , None ),
312
318
(True , None ),
313
- (True , pd ._libs . NaT if pd else None ),
319
+ (True , pd .NaT if pd else None ),
314
320
(True , np .NaN if pd else None ),
315
321
(True , 42 ),
316
322
],
@@ -326,7 +332,7 @@ def test_take(dtype, allow_fill, fill_value):
326
332
else datetime .time (0 , 42 , 42 , 424242 )
327
333
)
328
334
else :
329
- expected_fill = None
335
+ expected_fill = pd . NaT
330
336
b = a .take ([1 , - 1 , 3 ], allow_fill = True , fill_value = fill_value )
331
337
expect = [sample_values [1 ], expected_fill , sample_values [3 ]]
332
338
else :
@@ -370,7 +376,7 @@ def test__concat_same_type_not_same_type(dtype):
370
376
371
377
@for_date_and_time
372
378
def test_dropna (dtype ):
373
- assert np .array_equal (_make_one (dtype ).dropna (), _make_one (dtype )[:2 ])
379
+ np .testing . assert_array_equal (_make_one (dtype ).dropna (), _make_one (dtype )[:2 ])
374
380
375
381
376
382
@pytest .mark .parametrize (
@@ -398,14 +404,18 @@ def test_fillna(dtype, value, meth, limit, expect):
398
404
elif value is not None :
399
405
value = sample_values [value ]
400
406
expect = cls ([None if i is None else sample_values [i ] for i in expect ])
401
- assert np .array_equal (a .fillna (value , meth , limit ), expect )
407
+ np .testing .assert_array_equal (
408
+ a .fillna (value , meth , limit )._ndarray , expect ._ndarray
409
+ )
402
410
403
411
404
412
@for_date_and_time
405
413
def test_unique (dtype ):
406
414
cls = _cls (dtype )
407
415
sample_values = SAMPLE_VALUES [dtype ]
408
- assert np .array_equal (cls (sample_values * 3 ).unique (), cls (sample_values ),)
416
+ np .testing .assert_array_equal (
417
+ cls (sample_values * 3 ).unique (), cls (sample_values ),
418
+ )
409
419
410
420
411
421
@for_date_and_time
@@ -421,7 +431,7 @@ def test_astype_copy(dtype):
421
431
b = a .astype (a .dtype , copy = True )
422
432
assert b is not a
423
433
assert b .__class__ is a .__class__
424
- assert np .array_equal ( b , a )
434
+ np .testing . assert_array_equal ( b . _ndarray , a . _ndarray )
425
435
426
436
427
437
@pytest .mark .parametrize (
@@ -452,7 +462,7 @@ def test_asdatetime(dtype, same):
452
462
453
463
b = a .astype (dt , copy = copy )
454
464
assert b is not a ._ndarray
455
- assert np .array_equal (b [:2 ], a ._ndarray [:2 ])
465
+ np .testing . assert_array_equal (b [:2 ], a ._ndarray [:2 ])
456
466
assert pd .isna (b [2 ]) and str (b [2 ]) == "NaT"
457
467
458
468
@@ -482,7 +492,7 @@ def test_astimedelta(dtype):
482
492
483
493
a = _cls ("dbtime" )([t , None ])
484
494
b = a .astype (dtype )
485
- np .array_equal (b [:1 ], expect )
495
+ np .testing . assert_array_equal (b [:1 ], expect )
486
496
assert pd .isna (b [1 ]) and str (b [1 ]) == "NaT"
487
497
488
498
@@ -531,21 +541,21 @@ def test_min_max_median(dtype):
531
541
)
532
542
533
543
empty = cls ([])
534
- assert empty .min () is None
535
- assert empty .max () is None
544
+ assert empty .min () is pd . NaT
545
+ assert empty .max () is pd . NaT
536
546
if pandas_release >= (1 , 2 ):
537
- assert empty .median () is None
547
+ assert empty .median () is pd . NaT
538
548
empty = cls ([None ])
539
- assert empty .min () is None
540
- assert empty .max () is None
541
- assert empty .min (skipna = False ) is None
542
- assert empty .max (skipna = False ) is None
549
+ assert empty .min () is pd . NaT
550
+ assert empty .max () is pd . NaT
551
+ assert empty .min (skipna = False ) is pd . NaT
552
+ assert empty .max (skipna = False ) is pd . NaT
543
553
if pandas_release >= (1 , 2 ):
544
554
with pytest .warns (RuntimeWarning , match = "empty slice" ):
545
555
# It's weird that we get the warning here, and not
546
556
# below. :/
547
- assert empty .median () is None
548
- assert empty .median (skipna = False ) is None
557
+ assert empty .median () is pd . NaT
558
+ assert empty .median (skipna = False ) is pd . NaT
549
559
550
560
a = _make_one (dtype )
551
561
assert a .min () == sample_values [0 ]
@@ -563,14 +573,14 @@ def test_date_add():
563
573
times = _cls ("dbtime" )(SAMPLE_VALUES ["dbtime" ])
564
574
expect = dates .astype ("datetime64" ) + times .astype ("timedelta64" )
565
575
566
- assert np .array_equal (dates + times , expect )
567
- assert np .array_equal (times + dates , expect )
576
+ np .testing . assert_array_equal (dates + times , expect )
577
+ np .testing . assert_array_equal (times + dates , expect )
568
578
569
579
do = pd .DateOffset (days = 1 )
570
580
expect = dates .astype ("object" ) + do
571
- assert np .array_equal (dates + do , expect )
581
+ np .testing . assert_array_equal (dates + do , expect )
572
582
if pandas_release >= (1 , 1 ):
573
- assert np .array_equal (do + dates , expect )
583
+ np .testing . assert_array_equal (do + dates , expect )
574
584
575
585
with pytest .raises (TypeError ):
576
586
dates + times .astype ("timedelta64" )
@@ -587,8 +597,8 @@ def test_date_add():
587
597
588
598
do = pd .Series ([pd .DateOffset (days = i ) for i in range (4 )])
589
599
expect = dates .astype ("object" ) + do
590
- assert np .array_equal (dates + do , expect )
591
- assert np .array_equal (do + dates , expect )
600
+ np .testing . assert_array_equal (dates + do , expect )
601
+ np .testing . assert_array_equal (do + dates , expect )
592
602
593
603
594
604
def test_date_sub ():
@@ -602,11 +612,11 @@ def test_date_sub():
602
612
)
603
613
)
604
614
expect = dates .astype ("datetime64" ) - dates2 .astype ("datetime64" )
605
- assert np .array_equal (dates - dates2 , expect )
615
+ np .testing . assert_array_equal (dates - dates2 , expect )
606
616
607
617
do = pd .DateOffset (days = 1 )
608
618
expect = dates .astype ("object" ) - do
609
- assert np .array_equal (dates - do , expect )
619
+ np .testing . assert_array_equal (dates - do , expect )
610
620
611
621
with pytest .raises (TypeError ):
612
622
dates - 42
@@ -620,4 +630,4 @@ def test_date_sub():
620
630
621
631
do = pd .Series ([pd .DateOffset (days = i ) for i in range (4 )])
622
632
expect = dates .astype ("object" ) - do
623
- assert np .array_equal (dates - do , expect )
633
+ np .testing . assert_array_equal (dates - do , expect )
0 commit comments