Skip to content

Commit

Permalink
CLN: update imports in tests (pandas-dev#29275)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and proost committed Dec 19, 2019
1 parent b613059 commit 0700bfe
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 78 deletions.
65 changes: 31 additions & 34 deletions pandas/tests/scalar/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import pandas as pd
from pandas import NaT, Period, Timedelta, Timestamp, offsets
import pandas.core.indexes.period as period
import pandas.util.testing as tm


Expand Down Expand Up @@ -942,7 +941,7 @@ def test_equal(self):
assert self.january1 == self.january2

def test_equal_Raises_Value(self):
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
self.january1 == self.day

def test_notEqual(self):
Expand All @@ -953,7 +952,7 @@ def test_greater(self):
assert self.february > self.january1

def test_greater_Raises_Value(self):
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
self.january1 > self.day

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

def test_greaterEqual_Raises_Value(self):
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
self.january1 >= self.day

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

def test_smallerEqual_Raises_Value(self):
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
self.january1 <= self.day

def test_smallerEqual_Raises_Type(self):
Expand All @@ -985,7 +984,7 @@ def test_smaller(self):
assert self.january1 < self.february

def test_smaller_Raises_Value(self):
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
self.january1 < self.day

def test_smaller_Raises_Type(self):
Expand Down Expand Up @@ -1026,7 +1025,7 @@ def test_sub_delta(self):
result = left - right
assert result == 4 * right.freq

with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
left - Period("2007-01", freq="M")

def test_add_integer(self):
Expand Down Expand Up @@ -1097,16 +1096,16 @@ def test_sub(self):
assert per2 - per1 == 14 * off

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

@pytest.mark.parametrize("n", [1, 2, 3, 4])
def test_sub_n_gt_1_ticks(self, tick_classes, n):
# GH 23878
p1 = pd.Period("19910905", freq=tick_classes(n))
p2 = pd.Period("19920406", freq=tick_classes(n))
p1 = Period("19910905", freq=tick_classes(n))
p2 = Period("19920406", freq=tick_classes(n))

expected = pd.Period(str(p2), freq=p2.freq.base) - pd.Period(
expected = Period(str(p2), freq=p2.freq.base) - Period(
str(p1), freq=p1.freq.base
)

Expand All @@ -1117,23 +1116,21 @@ def test_sub_n_gt_1_ticks(self, tick_classes, n):
@pytest.mark.parametrize(
"offset, kwd_name",
[
(pd.offsets.YearEnd, "month"),
(pd.offsets.QuarterEnd, "startingMonth"),
(pd.offsets.MonthEnd, None),
(pd.offsets.Week, "weekday"),
(offsets.YearEnd, "month"),
(offsets.QuarterEnd, "startingMonth"),
(offsets.MonthEnd, None),
(offsets.Week, "weekday"),
],
)
def test_sub_n_gt_1_offsets(self, offset, kwd_name, n, normalize):
# GH 23878
kwds = {kwd_name: 3} if kwd_name is not None else {}
p1_d = "19910905"
p2_d = "19920406"
p1 = pd.Period(p1_d, freq=offset(n, normalize, **kwds))
p2 = pd.Period(p2_d, freq=offset(n, normalize, **kwds))
p1 = Period(p1_d, freq=offset(n, normalize, **kwds))
p2 = Period(p2_d, freq=offset(n, normalize, **kwds))

expected = pd.Period(p2_d, freq=p2.freq.base) - pd.Period(
p1_d, freq=p1.freq.base
)
expected = Period(p2_d, freq=p2.freq.base) - Period(p1_d, freq=p1.freq.base)

assert (p2 - p1) == expected

Expand All @@ -1152,14 +1149,14 @@ def test_add_offset(self):
np.timedelta64(365, "D"),
timedelta(365),
]:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
p + o

if isinstance(o, np.timedelta64):
with pytest.raises(TypeError):
o + p
else:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
o + p

for freq in ["M", "2M", "3M"]:
Expand All @@ -1179,14 +1176,14 @@ def test_add_offset(self):
np.timedelta64(365, "D"),
timedelta(365),
]:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
p + o

if isinstance(o, np.timedelta64):
with pytest.raises(TypeError):
o + p
else:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
o + p

# freq is Tick
Expand Down Expand Up @@ -1226,14 +1223,14 @@ def test_add_offset(self):
np.timedelta64(4, "h"),
timedelta(hours=23),
]:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
p + o

if isinstance(o, np.timedelta64):
with pytest.raises(TypeError):
o + p
else:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
o + p

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

if isinstance(o, np.timedelta64):
with pytest.raises(TypeError):
o + p
else:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
o + p

def test_add_offset_nat(self):
Expand Down Expand Up @@ -1376,7 +1373,7 @@ def test_sub_offset(self):
np.timedelta64(365, "D"),
timedelta(365),
]:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
p - o

for freq in ["M", "2M", "3M"]:
Expand All @@ -1391,7 +1388,7 @@ def test_sub_offset(self):
np.timedelta64(365, "D"),
timedelta(365),
]:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
p - o

# freq is Tick
Expand All @@ -1411,7 +1408,7 @@ def test_sub_offset(self):
np.timedelta64(4, "h"),
timedelta(hours=23),
]:
with pytest.raises(period.IncompatibleFrequency):
with pytest.raises(IncompatibleFrequency):
p - o

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

def test_sub_offset_nat(self):
Expand Down Expand Up @@ -1530,10 +1527,10 @@ def test_period_ops_offset(self):
assert result == exp

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

with pytest.raises(period.IncompatibleFrequency, match=msg):
with pytest.raises(IncompatibleFrequency, match=msg):
p - offsets.Hour(2)


Expand Down
28 changes: 14 additions & 14 deletions pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest

import pandas as pd
from pandas import NaT, Timedelta, Timestamp
from pandas import NaT, Timedelta, Timestamp, offsets
from pandas.core import ops
import pandas.util.testing as tm

Expand All @@ -28,7 +28,7 @@ class TestTimedeltaAdditionSubtraction:
timedelta(seconds=10),
np.timedelta64(10, "s"),
np.timedelta64(10000000000, "ns"),
pd.offsets.Second(10),
offsets.Second(10),
],
)
def test_td_add_sub_ten_seconds(self, ten_seconds):
Expand All @@ -50,7 +50,7 @@ def test_td_add_sub_ten_seconds(self, ten_seconds):
Timedelta("1 days, 00:00:10"),
timedelta(days=1, seconds=10),
np.timedelta64(1, "D") + np.timedelta64(10, "s"),
pd.offsets.Day() + pd.offsets.Second(10),
offsets.Day() + offsets.Second(10),
],
)
def test_td_add_sub_one_day_ten_seconds(self, one_day_ten_secs):
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_td_add_timedelta64(self, op):
def test_td_add_offset(self, op):
td = Timedelta(10, unit="d")

result = op(td, pd.offsets.Hour(6))
result = op(td, offsets.Hour(6))
assert isinstance(result, Timedelta)
assert result == Timedelta(days=10, hours=6)

Expand Down Expand Up @@ -167,7 +167,7 @@ def test_td_sub_td64_nat(self):

def test_td_sub_offset(self):
td = Timedelta(10, unit="d")
result = td - pd.offsets.Hour(1)
result = td - offsets.Hour(1)
assert isinstance(result, Timedelta)
assert result == Timedelta(239, unit="h")

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

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

Expand Down Expand Up @@ -306,7 +306,7 @@ def test_td_div_timedeltalike_scalar(self):
# GH#19738
td = Timedelta(10, unit="d")

result = td / pd.offsets.Hour(1)
result = td / offsets.Hour(1)
assert result == 240

assert td / td == 1
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_td_div_nan(self, nan):
def test_td_rdiv_timedeltalike_scalar(self):
# GH#19738
td = Timedelta(10, unit="d")
result = pd.offsets.Hour(1) / td
result = offsets.Hour(1) / td
assert result == 1 / 240.0

assert np.timedelta64(60, "h") / td == 0.25
Expand Down Expand Up @@ -370,8 +370,8 @@ def test_td_floordiv_null_scalar(self):
def test_td_floordiv_offsets(self):
# GH#19738
td = Timedelta(hours=3, minutes=4)
assert td // pd.offsets.Hour(1) == 3
assert td // pd.offsets.Minute(2) == 92
assert td // offsets.Hour(1) == 3
assert td // offsets.Minute(2) == 92

def test_td_floordiv_invalid_scalar(self):
# GH#18846
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_td_rfloordiv_null_scalar(self):

def test_td_rfloordiv_offsets(self):
# GH#19738
assert pd.offsets.Hour(1) // Timedelta(minutes=25) == 2
assert offsets.Hour(1) // Timedelta(minutes=25) == 2

def test_td_rfloordiv_invalid_scalar(self):
# GH#18846
Expand Down Expand Up @@ -532,7 +532,7 @@ def test_mod_offset(self):
# GH#19365
td = Timedelta(hours=37)

result = td % pd.offsets.Hour(5)
result = td % offsets.Hour(5)
assert isinstance(result, Timedelta)
assert result == Timedelta(hours=2)

Expand Down Expand Up @@ -633,7 +633,7 @@ def test_divmod_offset(self):
# GH#19365
td = Timedelta(days=2, hours=6)

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

def test_rdivmod_offset(self):
result = divmod(pd.offsets.Hour(54), Timedelta(hours=-4))
result = divmod(offsets.Hour(54), Timedelta(hours=-4))
assert result[0] == -14
assert isinstance(result[1], Timedelta)
assert result[1] == Timedelta(hours=-2)
Expand Down
Loading

0 comments on commit 0700bfe

Please sign in to comment.