2
2
import numpy as np
3
3
import pytest
4
4
5
- import pandas ._libs .tslib as tslib
6
-
7
5
import pandas as pd
8
- from pandas import DatetimeIndex , Index , Period , PeriodIndex , Series
6
+ from pandas import DatetimeIndex , Index , NaT , Period , PeriodIndex , Series
9
7
from pandas .core .arrays import PeriodArray
10
8
from pandas .tests .test_base import Ops
11
9
import pandas .util .testing as tm
@@ -29,13 +27,13 @@ def test_ops_properties(self):
29
27
def test_minmax (self ):
30
28
31
29
# monotonic
32
- idx1 = pd .PeriodIndex ([pd . NaT , '2011-01-01' , '2011-01-02' ,
30
+ idx1 = pd .PeriodIndex ([NaT , '2011-01-01' , '2011-01-02' ,
33
31
'2011-01-03' ], freq = 'D' )
34
32
assert idx1 .is_monotonic
35
33
36
34
# non-monotonic
37
- idx2 = pd .PeriodIndex (['2011-01-01' , pd . NaT , '2011-01-03' ,
38
- '2011-01-02' , pd . NaT ], freq = 'D' )
35
+ idx2 = pd .PeriodIndex (['2011-01-01' , NaT , '2011-01-03' ,
36
+ '2011-01-02' , NaT ], freq = 'D' )
39
37
assert not idx2 .is_monotonic
40
38
41
39
for idx in [idx1 , idx2 ]:
@@ -50,15 +48,15 @@ def test_minmax(self):
50
48
# Return NaT
51
49
obj = PeriodIndex ([], freq = 'M' )
52
50
result = getattr (obj , op )()
53
- assert result is tslib . NaT
51
+ assert result is NaT
54
52
55
- obj = PeriodIndex ([pd . NaT ], freq = 'M' )
53
+ obj = PeriodIndex ([NaT ], freq = 'M' )
56
54
result = getattr (obj , op )()
57
- assert result is tslib . NaT
55
+ assert result is NaT
58
56
59
- obj = PeriodIndex ([pd . NaT , pd . NaT , pd . NaT ], freq = 'M' )
57
+ obj = PeriodIndex ([NaT , NaT , NaT ], freq = 'M' )
60
58
result = getattr (obj , op )()
61
- assert result is tslib . NaT
59
+ assert result is NaT
62
60
63
61
def test_numpy_minmax (self ):
64
62
pr = pd .period_range (start = '2016-01-15' , end = '2016-01-20' )
@@ -113,7 +111,7 @@ def test_value_counts_unique(self):
113
111
114
112
idx = PeriodIndex (['2013-01-01 09:00' , '2013-01-01 09:00' ,
115
113
'2013-01-01 09:00' , '2013-01-01 08:00' ,
116
- '2013-01-01 08:00' , pd . NaT ], freq = 'H' )
114
+ '2013-01-01 08:00' , NaT ], freq = 'H' )
117
115
118
116
exp_idx = PeriodIndex (['2013-01-01 09:00' , '2013-01-01 08:00' ],
119
117
freq = 'H' )
@@ -123,7 +121,7 @@ def test_value_counts_unique(self):
123
121
tm .assert_series_equal (obj .value_counts (), expected )
124
122
125
123
exp_idx = PeriodIndex (['2013-01-01 09:00' , '2013-01-01 08:00' ,
126
- pd . NaT ], freq = 'H' )
124
+ NaT ], freq = 'H' )
127
125
expected = Series ([3 , 2 , 1 ], index = exp_idx )
128
126
129
127
for obj in [idx , Series (idx )]:
@@ -284,9 +282,9 @@ def test_order(self):
284
282
'2011-01-03' , '2011-01-05' ],
285
283
freq = 'D' , name = 'idx2' )
286
284
287
- idx3 = PeriodIndex ([pd . NaT , '2011-01-03' , '2011-01-05' ,
288
- '2011-01-02' , pd . NaT ], freq = 'D' , name = 'idx3' )
289
- exp3 = PeriodIndex ([pd . NaT , pd . NaT , '2011-01-02' , '2011-01-03' ,
285
+ idx3 = PeriodIndex ([NaT , '2011-01-03' , '2011-01-05' ,
286
+ '2011-01-02' , NaT ], freq = 'D' , name = 'idx3' )
287
+ exp3 = PeriodIndex ([NaT , NaT , '2011-01-02' , '2011-01-03' ,
290
288
'2011-01-05' ], freq = 'D' , name = 'idx3' )
291
289
292
290
for idx , expected in [(idx1 , exp1 ), (idx2 , exp2 ), (idx3 , exp3 )]:
@@ -338,8 +336,8 @@ def test_repeat(self):
338
336
tm .assert_index_equal (res , exp )
339
337
340
338
def test_nat (self ):
341
- assert pd .PeriodIndex ._na_value is pd . NaT
342
- assert pd .PeriodIndex ([], freq = 'M' )._na_value is pd . NaT
339
+ assert pd .PeriodIndex ._na_value is NaT
340
+ assert pd .PeriodIndex ([], freq = 'M' )._na_value is NaT
343
341
344
342
idx = pd .PeriodIndex (['2011-01-01' , '2011-01-02' ], freq = 'D' )
345
343
assert idx ._can_hold_na
@@ -460,10 +458,10 @@ def test_pi_comp_period_nat(self):
460
458
f = lambda x : pd .Period ('2011-03' , freq = 'M' ) == x
461
459
self ._check (idx , f , exp )
462
460
463
- f = lambda x : x == tslib . NaT
461
+ f = lambda x : x == NaT
464
462
exp = np .array ([False , False , False , False ], dtype = np .bool )
465
463
self ._check (idx , f , exp )
466
- f = lambda x : tslib . NaT == x
464
+ f = lambda x : NaT == x
467
465
self ._check (idx , f , exp )
468
466
469
467
f = lambda x : x != pd .Period ('2011-03' , freq = 'M' )
@@ -472,10 +470,10 @@ def test_pi_comp_period_nat(self):
472
470
f = lambda x : pd .Period ('2011-03' , freq = 'M' ) != x
473
471
self ._check (idx , f , exp )
474
472
475
- f = lambda x : x != tslib . NaT
473
+ f = lambda x : x != NaT
476
474
exp = np .array ([True , True , True , True ], dtype = np .bool )
477
475
self ._check (idx , f , exp )
478
- f = lambda x : tslib . NaT != x
476
+ f = lambda x : NaT != x
479
477
self ._check (idx , f , exp )
480
478
481
479
f = lambda x : pd .Period ('2011-03' , freq = 'M' ) >= x
@@ -486,11 +484,11 @@ def test_pi_comp_period_nat(self):
486
484
exp = np .array ([True , False , False , False ], dtype = np .bool )
487
485
self ._check (idx , f , exp )
488
486
489
- f = lambda x : x > tslib . NaT
487
+ f = lambda x : x > NaT
490
488
exp = np .array ([False , False , False , False ], dtype = np .bool )
491
489
self ._check (idx , f , exp )
492
490
493
- f = lambda x : tslib . NaT >= x
491
+ f = lambda x : NaT >= x
494
492
exp = np .array ([False , False , False , False ], dtype = np .bool )
495
493
self ._check (idx , f , exp )
496
494
0 commit comments