17
17
from pandas import (
18
18
DataFrame ,
19
19
DatetimeIndex ,
20
+ Index ,
20
21
NaT ,
21
22
Series ,
22
23
Timedelta ,
26
27
timedelta_range ,
27
28
)
28
29
import pandas ._testing as tm
29
- from pandas .core .api import NumericIndex
30
30
from pandas .core .arrays import PandasArray
31
31
from pandas .tests .arithmetic .common import (
32
32
assert_invalid_addsub_type ,
@@ -68,9 +68,7 @@ class TestTimedelta64ArrayLikeComparisons:
68
68
def test_compare_timedelta64_zerodim (self , box_with_array ):
69
69
# GH#26689 should unbox when comparing with zerodim array
70
70
box = box_with_array
71
- xbox = (
72
- box_with_array if box_with_array not in [pd .Index , pd .array ] else np .ndarray
73
- )
71
+ xbox = box_with_array if box_with_array not in [Index , pd .array ] else np .ndarray
74
72
75
73
tdi = timedelta_range ("2H" , periods = 4 )
76
74
other = np .array (tdi .to_numpy ()[0 ])
@@ -93,7 +91,7 @@ def test_compare_timedelta64_zerodim(self, box_with_array):
93
91
def test_compare_timedeltalike_scalar (self , box_with_array , td_scalar ):
94
92
# regression test for GH#5963
95
93
box = box_with_array
96
- xbox = box if box not in [pd . Index , pd .array ] else np .ndarray
94
+ xbox = box if box not in [Index , pd .array ] else np .ndarray
97
95
98
96
ser = Series ([timedelta (days = 1 ), timedelta (days = 2 )])
99
97
ser = tm .box_expected (ser , box )
@@ -489,7 +487,7 @@ def test_addition_ops(self):
489
487
# random indexes
490
488
msg = "Addition/subtraction of integers and integer-arrays"
491
489
with pytest .raises (TypeError , match = msg ):
492
- tdi + NumericIndex ([1 , 2 , 3 ], dtype = np .int64 )
490
+ tdi + Index ([1 , 2 , 3 ], dtype = np .int64 )
493
491
494
492
# this is a union!
495
493
# pytest.raises(TypeError, lambda : Index([1,2,3]) + tdi)
@@ -600,7 +598,7 @@ def test_tdi_iadd_timedeltalike(self, two_hours, box_with_array):
600
598
orig_rng = rng
601
599
rng += two_hours
602
600
tm .assert_equal (rng , expected )
603
- if box_with_array is not pd . Index :
601
+ if box_with_array is not Index :
604
602
# Check that operation is actually inplace
605
603
tm .assert_equal (orig_rng , expected )
606
604
@@ -615,7 +613,7 @@ def test_tdi_isub_timedeltalike(self, two_hours, box_with_array):
615
613
orig_rng = rng
616
614
rng -= two_hours
617
615
tm .assert_equal (rng , expected )
618
- if box_with_array is not pd . Index :
616
+ if box_with_array is not Index :
619
617
# Check that operation is actually inplace
620
618
tm .assert_equal (orig_rng , expected )
621
619
@@ -1119,7 +1117,7 @@ def test_td64arr_addsub_numeric_scalar_invalid(self, box_with_array, other):
1119
1117
"vec" ,
1120
1118
[
1121
1119
np .array ([1 , 2 , 3 ]),
1122
- pd . Index ([1 , 2 , 3 ]),
1120
+ Index ([1 , 2 , 3 ]),
1123
1121
Series ([1 , 2 , 3 ]),
1124
1122
DataFrame ([[1 , 2 , 3 ]]),
1125
1123
],
@@ -1292,7 +1290,7 @@ def test_td64arr_add_sub_offset_index(self, names, box_with_array):
1292
1290
exname = get_expected_name (box , names )
1293
1291
1294
1292
tdi = TimedeltaIndex (["1 days 00:00:00" , "3 days 04:00:00" ], name = names [0 ])
1295
- other = pd . Index ([offsets .Hour (n = 1 ), offsets .Minute (n = - 2 )], name = names [1 ])
1293
+ other = Index ([offsets .Hour (n = 1 ), offsets .Minute (n = - 2 )], name = names [1 ])
1296
1294
other = np .array (other ) if box in [tm .to_array , pd .array ] else other
1297
1295
1298
1296
expected = TimedeltaIndex (
@@ -1350,7 +1348,7 @@ def test_td64arr_add_sub_offset_array(self, box_with_array):
1350
1348
def test_td64arr_with_offset_series (self , names , box_with_array ):
1351
1349
# GH#18849
1352
1350
box = box_with_array
1353
- box2 = Series if box in [pd . Index , tm .to_array , pd .array ] else box
1351
+ box2 = Series if box in [Index , tm .to_array , pd .array ] else box
1354
1352
exname = get_expected_name (box , names )
1355
1353
1356
1354
tdi = TimedeltaIndex (["1 days 00:00:00" , "3 days 04:00:00" ], name = names [0 ])
@@ -1379,7 +1377,7 @@ def test_td64arr_with_offset_series(self, names, box_with_array):
1379
1377
res3 = obj - other
1380
1378
tm .assert_equal (res3 , expected_sub )
1381
1379
1382
- @pytest .mark .parametrize ("obox" , [np .array , pd . Index , Series ])
1380
+ @pytest .mark .parametrize ("obox" , [np .array , Index , Series ])
1383
1381
def test_td64arr_addsub_anchored_offset_arraylike (self , obox , box_with_array ):
1384
1382
# GH#18824
1385
1383
tdi = TimedeltaIndex (["1 days 00:00:00" , "3 days 04:00:00" ])
@@ -1418,7 +1416,7 @@ def test_td64arr_add_sub_object_array(self, box_with_array):
1418
1416
with tm .assert_produces_warning (PerformanceWarning ):
1419
1417
result = tdarr + other
1420
1418
1421
- expected = pd . Index (
1419
+ expected = Index (
1422
1420
[Timedelta (days = 2 ), Timedelta (days = 4 ), Timestamp ("2000-01-07" )]
1423
1421
)
1424
1422
expected = tm .box_expected (expected , xbox ).astype (object )
@@ -1432,7 +1430,7 @@ def test_td64arr_add_sub_object_array(self, box_with_array):
1432
1430
with tm .assert_produces_warning (PerformanceWarning ):
1433
1431
result = other - tdarr
1434
1432
1435
- expected = pd . Index ([Timedelta (0 ), Timedelta (0 ), Timestamp ("2000-01-01" )])
1433
+ expected = Index ([Timedelta (0 ), Timedelta (0 ), Timestamp ("2000-01-01" )])
1436
1434
expected = tm .box_expected (expected , xbox ).astype (object )
1437
1435
tm .assert_equal (result , expected )
1438
1436
@@ -1486,7 +1484,7 @@ def test_tdi_mul_int_array(self, box_with_array):
1486
1484
1487
1485
def test_tdi_mul_int_series (self , box_with_array ):
1488
1486
box = box_with_array
1489
- xbox = Series if box in [pd . Index , tm .to_array , pd .array ] else box
1487
+ xbox = Series if box in [Index , tm .to_array , pd .array ] else box
1490
1488
1491
1489
idx = TimedeltaIndex (np .arange (5 , dtype = "int64" ))
1492
1490
expected = TimedeltaIndex (np .arange (5 , dtype = "int64" ) ** 2 )
@@ -1499,7 +1497,7 @@ def test_tdi_mul_int_series(self, box_with_array):
1499
1497
1500
1498
def test_tdi_mul_float_series (self , box_with_array ):
1501
1499
box = box_with_array
1502
- xbox = Series if box in [pd . Index , tm .to_array , pd .array ] else box
1500
+ xbox = Series if box in [Index , tm .to_array , pd .array ] else box
1503
1501
1504
1502
idx = TimedeltaIndex (np .arange (5 , dtype = "int64" ))
1505
1503
idx = tm .box_expected (idx , box )
@@ -1516,9 +1514,9 @@ def test_tdi_mul_float_series(self, box_with_array):
1516
1514
"other" ,
1517
1515
[
1518
1516
np .arange (1 , 11 ),
1519
- NumericIndex (np .arange (1 , 11 ), np .int64 ),
1520
- NumericIndex (range (1 , 11 ), np .uint64 ),
1521
- NumericIndex (range (1 , 11 ), np .float64 ),
1517
+ Index (np .arange (1 , 11 ), np .int64 ),
1518
+ Index (range (1 , 11 ), np .uint64 ),
1519
+ Index (range (1 , 11 ), np .float64 ),
1522
1520
pd .RangeIndex (1 , 11 ),
1523
1521
],
1524
1522
ids = lambda x : type (x ).__name__ ,
@@ -1602,7 +1600,7 @@ def test_td64arr_div_tdlike_scalar(self, two_hours, box_with_array):
1602
1600
xbox = np .ndarray if box is pd .array else box
1603
1601
1604
1602
rng = timedelta_range ("1 days" , "10 days" , name = "foo" )
1605
- expected = NumericIndex ((np .arange (10 ) + 1 ) * 12 , dtype = np .float64 , name = "foo" )
1603
+ expected = Index ((np .arange (10 ) + 1 ) * 12 , dtype = np .float64 , name = "foo" )
1606
1604
1607
1605
rng = tm .box_expected (rng , box )
1608
1606
expected = tm .box_expected (expected , xbox )
@@ -1642,7 +1640,7 @@ def test_td64arr_div_tdlike_scalar_with_nat(self, two_hours, box_with_array):
1642
1640
xbox = np .ndarray if box is pd .array else box
1643
1641
1644
1642
rng = TimedeltaIndex (["1 days" , NaT , "2 days" ], name = "foo" )
1645
- expected = NumericIndex ([12 , np .nan , 24 ], dtype = np .float64 , name = "foo" )
1643
+ expected = Index ([12 , np .nan , 24 ], dtype = np .float64 , name = "foo" )
1646
1644
1647
1645
rng = tm .box_expected (rng , box )
1648
1646
expected = tm .box_expected (expected , xbox )
@@ -1660,7 +1658,7 @@ def test_td64arr_div_td64_ndarray(self, box_with_array):
1660
1658
xbox = np .ndarray if box is pd .array else box
1661
1659
1662
1660
rng = TimedeltaIndex (["1 days" , NaT , "2 days" ])
1663
- expected = NumericIndex ([12 , np .nan , 24 ], dtype = np .float64 )
1661
+ expected = Index ([12 , np .nan , 24 ], dtype = np .float64 )
1664
1662
1665
1663
rng = tm .box_expected (rng , box )
1666
1664
expected = tm .box_expected (expected , xbox )
@@ -1700,7 +1698,7 @@ def test_tdarr_div_length_mismatch(self, box_with_array):
1700
1698
msg = "Cannot divide vectors|Unable to coerce to Series"
1701
1699
for obj in [mismatched , mismatched [:2 ]]:
1702
1700
# one shorter, one longer
1703
- for other in [obj , np .array (obj ), pd . Index (obj )]:
1701
+ for other in [obj , np .array (obj ), Index (obj )]:
1704
1702
with pytest .raises (ValueError , match = msg ):
1705
1703
rng / other
1706
1704
with pytest .raises (ValueError , match = msg ):
@@ -1717,9 +1715,7 @@ def test_td64_div_object_mixed_result(self, box_with_array):
1717
1715
1718
1716
res = tdi / other
1719
1717
1720
- expected = pd .Index (
1721
- [1.0 , np .timedelta64 ("NaT" , "ns" ), orig [0 ], 1.5 ], dtype = object
1722
- )
1718
+ expected = Index ([1.0 , np .timedelta64 ("NaT" , "ns" ), orig [0 ], 1.5 ], dtype = object )
1723
1719
expected = tm .box_expected (expected , box_with_array , transpose = False )
1724
1720
if isinstance (expected , PandasArray ):
1725
1721
expected = expected .to_numpy ()
@@ -1730,7 +1726,7 @@ def test_td64_div_object_mixed_result(self, box_with_array):
1730
1726
1731
1727
res = tdi // other
1732
1728
1733
- expected = pd . Index ([1 , np .timedelta64 ("NaT" , "ns" ), orig [0 ], 1 ], dtype = object )
1729
+ expected = Index ([1 , np .timedelta64 ("NaT" , "ns" ), orig [0 ], 1 ], dtype = object )
1734
1730
expected = tm .box_expected (expected , box_with_array , transpose = False )
1735
1731
if isinstance (expected , PandasArray ):
1736
1732
expected = expected .to_numpy ()
@@ -1974,7 +1970,7 @@ def test_td64arr_floordiv_numeric_scalar(self, box_with_array, two):
1974
1970
1975
1971
@pytest .mark .parametrize (
1976
1972
"vector" ,
1977
- [np .array ([20 , 30 , 40 ]), pd . Index ([20 , 30 , 40 ]), Series ([20 , 30 , 40 ])],
1973
+ [np .array ([20 , 30 , 40 ]), Index ([20 , 30 , 40 ]), Series ([20 , 30 , 40 ])],
1978
1974
ids = lambda x : type (x ).__name__ ,
1979
1975
)
1980
1976
def test_td64arr_rmul_numeric_array (
@@ -2004,7 +2000,7 @@ def test_td64arr_rmul_numeric_array(
2004
2000
2005
2001
@pytest .mark .parametrize (
2006
2002
"vector" ,
2007
- [np .array ([20 , 30 , 40 ]), pd . Index ([20 , 30 , 40 ]), Series ([20 , 30 , 40 ])],
2003
+ [np .array ([20 , 30 , 40 ]), Index ([20 , 30 , 40 ]), Series ([20 , 30 , 40 ])],
2008
2004
ids = lambda x : type (x ).__name__ ,
2009
2005
)
2010
2006
def test_td64arr_div_numeric_array (
@@ -2118,8 +2114,8 @@ def test_td64arr_all_nat_div_object_dtype_numeric(self, box_with_array):
2118
2114
left = tm .box_expected (tdi , box_with_array )
2119
2115
right = np .array ([2 , 2.0 ], dtype = object )
2120
2116
2121
- expected = pd . Index ([np .timedelta64 ("NaT" , "ns" )] * 2 , dtype = object )
2122
- if box_with_array is not pd . Index :
2117
+ expected = Index ([np .timedelta64 ("NaT" , "ns" )] * 2 , dtype = object )
2118
+ if box_with_array is not Index :
2123
2119
expected = tm .box_expected (expected , box_with_array ).astype (object )
2124
2120
2125
2121
result = left / right
0 commit comments