Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: Consistent pandas.util.testing imports in pandas/tests/resample #29286

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions pandas/tests/resample/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
from pandas.core.indexes.period import PeriodIndex, period_range
from pandas.core.indexes.timedeltas import TimedeltaIndex, timedelta_range
import pandas.util.testing as tm
from pandas.util.testing import (
assert_almost_equal,
assert_frame_equal,
assert_index_equal,
assert_series_equal,
)

# a fixture value can be overridden by the test parameter value. Note that the
# value of the fixture can be overridden this way even if the test doesn't use
Expand Down Expand Up @@ -53,7 +47,7 @@ def test_asfreq(series_and_frame, freq, create_index):
result = obj.resample(freq).asfreq()
new_index = create_index(obj.index[0], obj.index[-1], freq=freq)
expected = obj.reindex(new_index)
assert_almost_equal(result, expected)
tm.assert_almost_equal(result, expected)


@pytest.mark.parametrize(
Expand All @@ -67,21 +61,21 @@ def test_asfreq_fill_value(series, create_index):
result = s.resample("1H").asfreq()
new_index = create_index(s.index[0], s.index[-1], freq="1H")
expected = s.reindex(new_index)
assert_series_equal(result, expected)
tm.assert_series_equal(result, expected)

frame = s.to_frame("value")
frame.iloc[1] = None
result = frame.resample("1H").asfreq(fill_value=4.0)
new_index = create_index(frame.index[0], frame.index[-1], freq="1H")
expected = frame.reindex(new_index, fill_value=4.0)
assert_frame_equal(result, expected)
tm.assert_frame_equal(result, expected)


@all_ts
def test_resample_interpolate(frame):
# # 12925
df = frame
assert_frame_equal(
tm.assert_frame_equal(
df.resample("1T").asfreq().interpolate(), df.resample("1T").interpolate()
)

Expand Down Expand Up @@ -113,9 +107,9 @@ def test_resample_empty_series(freq, empty_series, resample_method):
expected.index = s.index.asfreq(freq=freq)
else:
expected.index = s.index._shallow_copy(freq=freq)
assert_index_equal(result.index, expected.index)
tm.assert_index_equal(result.index, expected.index)
assert result.index.freq == expected.index.freq
assert_series_equal(result, expected, check_dtype=False)
tm.assert_series_equal(result, expected, check_dtype=False)


@all_ts
Expand All @@ -135,9 +129,9 @@ def test_resample_empty_dataframe(empty_frame, freq, resample_method):
expected.index = df.index.asfreq(freq=freq)
else:
expected.index = df.index._shallow_copy(freq=freq)
assert_index_equal(result.index, expected.index)
tm.assert_index_equal(result.index, expected.index)
assert result.index.freq == expected.index.freq
assert_almost_equal(result, expected, check_dtype=False)
tm.assert_almost_equal(result, expected, check_dtype=False)

# test size for GH13212 (currently stays as df)

Expand Down Expand Up @@ -186,12 +180,12 @@ def test_resample_loffset_arg_type(frame, create_index):
if isinstance(expected.index, TimedeltaIndex):
msg = "DataFrame are different"
with pytest.raises(AssertionError, match=msg):
assert_frame_equal(result_agg, expected)
tm.assert_frame_equal(result_agg, expected)
with pytest.raises(AssertionError, match=msg):
assert_frame_equal(result_how, expected)
tm.assert_frame_equal(result_how, expected)
else:
assert_frame_equal(result_agg, expected)
assert_frame_equal(result_how, expected)
tm.assert_frame_equal(result_agg, expected)
tm.assert_frame_equal(result_how, expected)


@all_ts
Expand All @@ -202,7 +196,7 @@ def test_apply_to_empty_series(empty_series):
result = s.resample(freq).apply(lambda x: 1)
expected = s.resample(freq).apply(np.sum)

assert_series_equal(result, expected, check_dtype=False)
tm.assert_series_equal(result, expected, check_dtype=False)


@all_ts
Expand All @@ -214,7 +208,7 @@ def test_resampler_is_iterable(series):
resampled = series.resample(freq)
for (rk, rv), (gk, gv) in zip(resampled, grouped):
assert rk == gk
assert_series_equal(rv, gv)
tm.assert_series_equal(rv, gv)


@all_ts
Expand Down
Loading