Skip to content

Commit 88dfc50

Browse files
committed
catch warnings in test_asof
1 parent d8db903 commit 88dfc50

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5026,7 +5026,7 @@ def sample(
50265026
)
50275027

50285028
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5029-
return self.take(locs, axis=axis, is_copy=False)
5029+
return self.take(locs, axis=axis)
50305030

50315031
_shared_docs[
50325032
"pipe"

pandas/tests/frame/methods/test_asof.py

+52-32
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
import pytest
33

44
from pandas import DataFrame, Series, Timestamp, date_range, to_datetime
5+
56
import pandas._testing as tm
67

8+
import pandas.util.testing as tm
9+
import warnings
10+
11+
warnings.simplefilter("error")
12+
13+
714

815
@pytest.fixture
916
def date_range_frame():
@@ -24,14 +31,18 @@ def test_basic(self, date_range_frame):
2431
df.loc[15:30, "A"] = np.nan
2532
dates = date_range("1/1/1990", periods=N * 3, freq="25s")
2633

27-
result = df.asof(dates)
28-
assert result.notna().all(1).all()
29-
lb = df.index[14]
30-
ub = df.index[30]
34+
with warnings.catch_warnings():
35+
warnings.simplefilter("ignore", FutureWarning)
36+
37+
result = df.asof(dates)
38+
assert result.notna().all(1).all()
39+
lb = df.index[14]
40+
ub = df.index[30]
3141

32-
dates = list(dates)
33-
result = df.asof(dates)
34-
assert result.notna().all(1).all()
42+
dates = list(dates)
43+
44+
result = df.asof(dates)
45+
assert result.notna().all(1).all()
3546

3647
mask = (result.index >= lb) & (result.index < ub)
3748
rs = result[mask]
@@ -43,40 +54,46 @@ def test_subset(self, date_range_frame):
4354
df.loc[4:8, "A"] = np.nan
4455
dates = date_range("1/1/1990", periods=N * 3, freq="25s")
4556

46-
# with a subset of A should be the same
47-
result = df.asof(dates, subset="A")
48-
expected = df.asof(dates)
49-
tm.assert_frame_equal(result, expected)
57+
with warnings.catch_warnings():
58+
warnings.simplefilter("ignore", FutureWarning)
5059

51-
# same with A/B
52-
result = df.asof(dates, subset=["A", "B"])
53-
expected = df.asof(dates)
54-
tm.assert_frame_equal(result, expected)
60+
# with a subset of A should be the same
61+
result = df.asof(dates, subset="A")
62+
expected = df.asof(dates)
63+
tm.assert_frame_equal(result, expected)
5564

56-
# B gives df.asof
57-
result = df.asof(dates, subset="B")
58-
expected = df.resample("25s", closed="right").ffill().reindex(dates)
59-
expected.iloc[20:] = 9
65+
# same with A/B
66+
result = df.asof(dates, subset=["A", "B"])
67+
expected = df.asof(dates)
68+
tm.assert_frame_equal(result, expected)
6069

61-
tm.assert_frame_equal(result, expected)
70+
# B gives df.asof
71+
result = df.asof(dates, subset="B")
72+
expected = df.resample("25s", closed="right").ffill().reindex(dates)
73+
expected.iloc[20:] = 9
74+
75+
tm.assert_frame_equal(result, expected)
6276

6377
def test_missing(self, date_range_frame):
6478
# GH 15118
6579
# no match found - `where` value before earliest date in index
6680
N = 10
6781
df = date_range_frame.iloc[:N].copy()
68-
result = df.asof("1989-12-31")
82+
with warnings.catch_warnings():
83+
warnings.simplefilter("ignore", FutureWarning)
6984

70-
expected = Series(
71-
index=["A", "B"], name=Timestamp("1989-12-31"), dtype=np.float64
72-
)
73-
tm.assert_series_equal(result, expected)
85+
result = df.asof("1989-12-31")
7486

75-
result = df.asof(to_datetime(["1989-12-31"]))
76-
expected = DataFrame(
77-
index=to_datetime(["1989-12-31"]), columns=["A", "B"], dtype="float64"
78-
)
79-
tm.assert_frame_equal(result, expected)
87+
expected = Series(
88+
index=["A", "B"], name=Timestamp("1989-12-31"), dtype=np.float64
89+
)
90+
tm.assert_series_equal(result, expected)
91+
92+
result = df.asof(to_datetime(["1989-12-31"]))
93+
expected = DataFrame(
94+
index=to_datetime(["1989-12-31"]), columns=["A", "B"], dtype="float64"
95+
)
96+
tm.assert_frame_equal(result, expected)
8097

8198
def test_all_nans(self, date_range_frame):
8299
# GH 15713
@@ -132,5 +149,8 @@ def test_time_zone_aware_index(self, stamp, expected):
132149
Timestamp("2018-01-01 22:35:10.550+00:00"),
133150
],
134151
)
135-
result = df.asof(stamp)
136-
tm.assert_series_equal(result, expected)
152+
with warnings.catch_warnings():
153+
warnings.simplefilter("ignore", FutureWarning)
154+
155+
result = df.asof(stamp)
156+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)