Skip to content

Commit 0700bfe

Browse files
jbrockmendelproost
authored andcommitted
CLN: update imports in tests (pandas-dev#29275)
1 parent b613059 commit 0700bfe

File tree

5 files changed

+75
-78
lines changed

5 files changed

+75
-78
lines changed

pandas/tests/scalar/period/test_period.py

+31-34
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import pandas as pd
1717
from pandas import NaT, Period, Timedelta, Timestamp, offsets
18-
import pandas.core.indexes.period as period
1918
import pandas.util.testing as tm
2019

2120

@@ -942,7 +941,7 @@ def test_equal(self):
942941
assert self.january1 == self.january2
943942

944943
def test_equal_Raises_Value(self):
945-
with pytest.raises(period.IncompatibleFrequency):
944+
with pytest.raises(IncompatibleFrequency):
946945
self.january1 == self.day
947946

948947
def test_notEqual(self):
@@ -953,7 +952,7 @@ def test_greater(self):
953952
assert self.february > self.january1
954953

955954
def test_greater_Raises_Value(self):
956-
with pytest.raises(period.IncompatibleFrequency):
955+
with pytest.raises(IncompatibleFrequency):
957956
self.january1 > self.day
958957

959958
def test_greater_Raises_Type(self):
@@ -964,7 +963,7 @@ def test_greaterEqual(self):
964963
assert self.january1 >= self.january2
965964

966965
def test_greaterEqual_Raises_Value(self):
967-
with pytest.raises(period.IncompatibleFrequency):
966+
with pytest.raises(IncompatibleFrequency):
968967
self.january1 >= self.day
969968

970969
with pytest.raises(TypeError):
@@ -974,7 +973,7 @@ def test_smallerEqual(self):
974973
assert self.january1 <= self.january2
975974

976975
def test_smallerEqual_Raises_Value(self):
977-
with pytest.raises(period.IncompatibleFrequency):
976+
with pytest.raises(IncompatibleFrequency):
978977
self.january1 <= self.day
979978

980979
def test_smallerEqual_Raises_Type(self):
@@ -985,7 +984,7 @@ def test_smaller(self):
985984
assert self.january1 < self.february
986985

987986
def test_smaller_Raises_Value(self):
988-
with pytest.raises(period.IncompatibleFrequency):
987+
with pytest.raises(IncompatibleFrequency):
989988
self.january1 < self.day
990989

991990
def test_smaller_Raises_Type(self):
@@ -1026,7 +1025,7 @@ def test_sub_delta(self):
10261025
result = left - right
10271026
assert result == 4 * right.freq
10281027

1029-
with pytest.raises(period.IncompatibleFrequency):
1028+
with pytest.raises(IncompatibleFrequency):
10301029
left - Period("2007-01", freq="M")
10311030

10321031
def test_add_integer(self):
@@ -1097,16 +1096,16 @@ def test_sub(self):
10971096
assert per2 - per1 == 14 * off
10981097

10991098
msg = r"Input has different freq=M from Period\(freq=D\)"
1100-
with pytest.raises(period.IncompatibleFrequency, match=msg):
1099+
with pytest.raises(IncompatibleFrequency, match=msg):
11011100
per1 - Period("2011-02", freq="M")
11021101

11031102
@pytest.mark.parametrize("n", [1, 2, 3, 4])
11041103
def test_sub_n_gt_1_ticks(self, tick_classes, n):
11051104
# GH 23878
1106-
p1 = pd.Period("19910905", freq=tick_classes(n))
1107-
p2 = pd.Period("19920406", freq=tick_classes(n))
1105+
p1 = Period("19910905", freq=tick_classes(n))
1106+
p2 = Period("19920406", freq=tick_classes(n))
11081107

1109-
expected = pd.Period(str(p2), freq=p2.freq.base) - pd.Period(
1108+
expected = Period(str(p2), freq=p2.freq.base) - Period(
11101109
str(p1), freq=p1.freq.base
11111110
)
11121111

@@ -1117,23 +1116,21 @@ def test_sub_n_gt_1_ticks(self, tick_classes, n):
11171116
@pytest.mark.parametrize(
11181117
"offset, kwd_name",
11191118
[
1120-
(pd.offsets.YearEnd, "month"),
1121-
(pd.offsets.QuarterEnd, "startingMonth"),
1122-
(pd.offsets.MonthEnd, None),
1123-
(pd.offsets.Week, "weekday"),
1119+
(offsets.YearEnd, "month"),
1120+
(offsets.QuarterEnd, "startingMonth"),
1121+
(offsets.MonthEnd, None),
1122+
(offsets.Week, "weekday"),
11241123
],
11251124
)
11261125
def test_sub_n_gt_1_offsets(self, offset, kwd_name, n, normalize):
11271126
# GH 23878
11281127
kwds = {kwd_name: 3} if kwd_name is not None else {}
11291128
p1_d = "19910905"
11301129
p2_d = "19920406"
1131-
p1 = pd.Period(p1_d, freq=offset(n, normalize, **kwds))
1132-
p2 = pd.Period(p2_d, freq=offset(n, normalize, **kwds))
1130+
p1 = Period(p1_d, freq=offset(n, normalize, **kwds))
1131+
p2 = Period(p2_d, freq=offset(n, normalize, **kwds))
11331132

1134-
expected = pd.Period(p2_d, freq=p2.freq.base) - pd.Period(
1135-
p1_d, freq=p1.freq.base
1136-
)
1133+
expected = Period(p2_d, freq=p2.freq.base) - Period(p1_d, freq=p1.freq.base)
11371134

11381135
assert (p2 - p1) == expected
11391136

@@ -1152,14 +1149,14 @@ def test_add_offset(self):
11521149
np.timedelta64(365, "D"),
11531150
timedelta(365),
11541151
]:
1155-
with pytest.raises(period.IncompatibleFrequency):
1152+
with pytest.raises(IncompatibleFrequency):
11561153
p + o
11571154

11581155
if isinstance(o, np.timedelta64):
11591156
with pytest.raises(TypeError):
11601157
o + p
11611158
else:
1162-
with pytest.raises(period.IncompatibleFrequency):
1159+
with pytest.raises(IncompatibleFrequency):
11631160
o + p
11641161

11651162
for freq in ["M", "2M", "3M"]:
@@ -1179,14 +1176,14 @@ def test_add_offset(self):
11791176
np.timedelta64(365, "D"),
11801177
timedelta(365),
11811178
]:
1182-
with pytest.raises(period.IncompatibleFrequency):
1179+
with pytest.raises(IncompatibleFrequency):
11831180
p + o
11841181

11851182
if isinstance(o, np.timedelta64):
11861183
with pytest.raises(TypeError):
11871184
o + p
11881185
else:
1189-
with pytest.raises(period.IncompatibleFrequency):
1186+
with pytest.raises(IncompatibleFrequency):
11901187
o + p
11911188

11921189
# freq is Tick
@@ -1226,14 +1223,14 @@ def test_add_offset(self):
12261223
np.timedelta64(4, "h"),
12271224
timedelta(hours=23),
12281225
]:
1229-
with pytest.raises(period.IncompatibleFrequency):
1226+
with pytest.raises(IncompatibleFrequency):
12301227
p + o
12311228

12321229
if isinstance(o, np.timedelta64):
12331230
with pytest.raises(TypeError):
12341231
o + p
12351232
else:
1236-
with pytest.raises(period.IncompatibleFrequency):
1233+
with pytest.raises(IncompatibleFrequency):
12371234
o + p
12381235

12391236
for freq in ["H", "2H", "3H"]:
@@ -1272,14 +1269,14 @@ def test_add_offset(self):
12721269
np.timedelta64(3200, "s"),
12731270
timedelta(hours=23, minutes=30),
12741271
]:
1275-
with pytest.raises(period.IncompatibleFrequency):
1272+
with pytest.raises(IncompatibleFrequency):
12761273
p + o
12771274

12781275
if isinstance(o, np.timedelta64):
12791276
with pytest.raises(TypeError):
12801277
o + p
12811278
else:
1282-
with pytest.raises(period.IncompatibleFrequency):
1279+
with pytest.raises(IncompatibleFrequency):
12831280
o + p
12841281

12851282
def test_add_offset_nat(self):
@@ -1376,7 +1373,7 @@ def test_sub_offset(self):
13761373
np.timedelta64(365, "D"),
13771374
timedelta(365),
13781375
]:
1379-
with pytest.raises(period.IncompatibleFrequency):
1376+
with pytest.raises(IncompatibleFrequency):
13801377
p - o
13811378

13821379
for freq in ["M", "2M", "3M"]:
@@ -1391,7 +1388,7 @@ def test_sub_offset(self):
13911388
np.timedelta64(365, "D"),
13921389
timedelta(365),
13931390
]:
1394-
with pytest.raises(period.IncompatibleFrequency):
1391+
with pytest.raises(IncompatibleFrequency):
13951392
p - o
13961393

13971394
# freq is Tick
@@ -1411,7 +1408,7 @@ def test_sub_offset(self):
14111408
np.timedelta64(4, "h"),
14121409
timedelta(hours=23),
14131410
]:
1414-
with pytest.raises(period.IncompatibleFrequency):
1411+
with pytest.raises(IncompatibleFrequency):
14151412
p - o
14161413

14171414
for freq in ["H", "2H", "3H"]:
@@ -1434,7 +1431,7 @@ def test_sub_offset(self):
14341431
np.timedelta64(3200, "s"),
14351432
timedelta(hours=23, minutes=30),
14361433
]:
1437-
with pytest.raises(period.IncompatibleFrequency):
1434+
with pytest.raises(IncompatibleFrequency):
14381435
p - o
14391436

14401437
def test_sub_offset_nat(self):
@@ -1530,10 +1527,10 @@ def test_period_ops_offset(self):
15301527
assert result == exp
15311528

15321529
msg = r"Input cannot be converted to Period\(freq=D\)"
1533-
with pytest.raises(period.IncompatibleFrequency, match=msg):
1530+
with pytest.raises(IncompatibleFrequency, match=msg):
15341531
p + offsets.Hour(2)
15351532

1536-
with pytest.raises(period.IncompatibleFrequency, match=msg):
1533+
with pytest.raises(IncompatibleFrequency, match=msg):
15371534
p - offsets.Hour(2)
15381535

15391536

pandas/tests/scalar/timedelta/test_arithmetic.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
import pandas as pd
11-
from pandas import NaT, Timedelta, Timestamp
11+
from pandas import NaT, Timedelta, Timestamp, offsets
1212
from pandas.core import ops
1313
import pandas.util.testing as tm
1414

@@ -28,7 +28,7 @@ class TestTimedeltaAdditionSubtraction:
2828
timedelta(seconds=10),
2929
np.timedelta64(10, "s"),
3030
np.timedelta64(10000000000, "ns"),
31-
pd.offsets.Second(10),
31+
offsets.Second(10),
3232
],
3333
)
3434
def test_td_add_sub_ten_seconds(self, ten_seconds):
@@ -50,7 +50,7 @@ def test_td_add_sub_ten_seconds(self, ten_seconds):
5050
Timedelta("1 days, 00:00:10"),
5151
timedelta(days=1, seconds=10),
5252
np.timedelta64(1, "D") + np.timedelta64(10, "s"),
53-
pd.offsets.Day() + pd.offsets.Second(10),
53+
offsets.Day() + offsets.Second(10),
5454
],
5555
)
5656
def test_td_add_sub_one_day_ten_seconds(self, one_day_ten_secs):
@@ -114,7 +114,7 @@ def test_td_add_timedelta64(self, op):
114114
def test_td_add_offset(self, op):
115115
td = Timedelta(10, unit="d")
116116

117-
result = op(td, pd.offsets.Hour(6))
117+
result = op(td, offsets.Hour(6))
118118
assert isinstance(result, Timedelta)
119119
assert result == Timedelta(days=10, hours=6)
120120

@@ -167,7 +167,7 @@ def test_td_sub_td64_nat(self):
167167

168168
def test_td_sub_offset(self):
169169
td = Timedelta(10, unit="d")
170-
result = td - pd.offsets.Hour(1)
170+
result = td - offsets.Hour(1)
171171
assert isinstance(result, Timedelta)
172172
assert result == Timedelta(239, unit="h")
173173

@@ -192,7 +192,7 @@ def test_td_rsub_nat(self):
192192
assert result is NaT
193193

194194
def test_td_rsub_offset(self):
195-
result = pd.offsets.Hour(1) - Timedelta(10, unit="d")
195+
result = offsets.Hour(1) - Timedelta(10, unit="d")
196196
assert isinstance(result, Timedelta)
197197
assert result == Timedelta(-239, unit="h")
198198

@@ -306,7 +306,7 @@ def test_td_div_timedeltalike_scalar(self):
306306
# GH#19738
307307
td = Timedelta(10, unit="d")
308308

309-
result = td / pd.offsets.Hour(1)
309+
result = td / offsets.Hour(1)
310310
assert result == 240
311311

312312
assert td / td == 1
@@ -342,7 +342,7 @@ def test_td_div_nan(self, nan):
342342
def test_td_rdiv_timedeltalike_scalar(self):
343343
# GH#19738
344344
td = Timedelta(10, unit="d")
345-
result = pd.offsets.Hour(1) / td
345+
result = offsets.Hour(1) / td
346346
assert result == 1 / 240.0
347347

348348
assert np.timedelta64(60, "h") / td == 0.25
@@ -370,8 +370,8 @@ def test_td_floordiv_null_scalar(self):
370370
def test_td_floordiv_offsets(self):
371371
# GH#19738
372372
td = Timedelta(hours=3, minutes=4)
373-
assert td // pd.offsets.Hour(1) == 3
374-
assert td // pd.offsets.Minute(2) == 92
373+
assert td // offsets.Hour(1) == 3
374+
assert td // offsets.Minute(2) == 92
375375

376376
def test_td_floordiv_invalid_scalar(self):
377377
# GH#18846
@@ -441,7 +441,7 @@ def test_td_rfloordiv_null_scalar(self):
441441

442442
def test_td_rfloordiv_offsets(self):
443443
# GH#19738
444-
assert pd.offsets.Hour(1) // Timedelta(minutes=25) == 2
444+
assert offsets.Hour(1) // Timedelta(minutes=25) == 2
445445

446446
def test_td_rfloordiv_invalid_scalar(self):
447447
# GH#18846
@@ -532,7 +532,7 @@ def test_mod_offset(self):
532532
# GH#19365
533533
td = Timedelta(hours=37)
534534

535-
result = td % pd.offsets.Hour(5)
535+
result = td % offsets.Hour(5)
536536
assert isinstance(result, Timedelta)
537537
assert result == Timedelta(hours=2)
538538

@@ -633,7 +633,7 @@ def test_divmod_offset(self):
633633
# GH#19365
634634
td = Timedelta(days=2, hours=6)
635635

636-
result = divmod(td, pd.offsets.Hour(-4))
636+
result = divmod(td, offsets.Hour(-4))
637637
assert result[0] == -14
638638
assert isinstance(result[1], Timedelta)
639639
assert result[1] == Timedelta(hours=-2)
@@ -653,7 +653,7 @@ def test_rdivmod_pytimedelta(self):
653653
assert result[1] == Timedelta(hours=6)
654654

655655
def test_rdivmod_offset(self):
656-
result = divmod(pd.offsets.Hour(54), Timedelta(hours=-4))
656+
result = divmod(offsets.Hour(54), Timedelta(hours=-4))
657657
assert result[0] == -14
658658
assert isinstance(result[1], Timedelta)
659659
assert result[1] == Timedelta(hours=-2)

0 commit comments

Comments
 (0)