Skip to content

Commit

Permalink
Address pytest deprecation warnings (#3889)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jul 5, 2022
1 parent d1927e3 commit d60cfa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,9 @@ def test_groupby() -> None:
# )
assert df.groupby("a").apply(lambda df: df[["c"]].sum()).sort("c")["c"][0] == 1

df_groups = df.groupby("a").groups().sort("a")
assert df_groups["a"].series_equal(pl.Series("a", ["a", "b", "c"]))
with pytest.deprecated_call():
df_groups = df.groupby("a").groups().sort("a")
assert df_groups["a"].series_equal(pl.Series("a", ["a", "b", "c"]))

with pytest.deprecated_call():
# TODO: find a way to avoid indexing into GroupBy
Expand All @@ -699,9 +700,10 @@ def test_groupby() -> None:
if subdf["a"][0] == "b":
assert subdf.shape == (3, 3)

assert df.groupby("a").get_group("c").shape == (1, 3)
assert df.groupby("a").get_group("b").shape == (3, 3)
assert df.groupby("a").get_group("a").shape == (2, 3)
with pytest.deprecated_call():
assert df.groupby("a").get_group("c").shape == (1, 3)
assert df.groupby("a").get_group("b").shape == (3, 3)
assert df.groupby("a").get_group("a").shape == (2, 3)

# Use lazy API in eager groupby
assert df.groupby("a").agg([pl.sum("b")]).shape == (3, 2)
Expand Down Expand Up @@ -2006,9 +2008,6 @@ def test_get_item() -> None:
# expression
assert df.select(pl.col("a")).frame_equal(pl.DataFrame({"a": [1.0, 2.0]}))

# numpy array
assert df[np.array([True, False])].frame_equal(pl.DataFrame({"a": [1.0], "b": [3]}))

# tuple. The first element refers to the rows, the second element to columns
assert df[:, :].frame_equal(df)

Expand All @@ -2025,12 +2024,16 @@ def test_get_item() -> None:
assert df[::2].frame_equal(pl.DataFrame({"a": [1.0], "b": [3]}))

# numpy array; assumed to be row indices if integers, or columns if strings
# TODO: add boolean mask support
df[np.array([1])].frame_equal(pl.DataFrame({"a": [2.0], "b": [4]}))
df[np.array(["a"])].frame_equal(pl.DataFrame({"a": [1.0, 2.0]}))
# note that we cannot use floats (even if they could be casted to integer without loss)
with pytest.raises(NotImplementedError):
_ = df[np.array([1.0])]
# using boolean masks with numpy is deprecated
with pytest.deprecated_call():
assert df[np.array([True, False])].frame_equal(
pl.DataFrame({"a": [1.0], "b": [3]})
)

# sequences (lists or tuples; tuple only if length != 2)
# if strings or list of expressions, assumed to be column names
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ def test_self_join() -> None:
).lazy()

out = (
df.join(ldf=df, left_on="manager_id", right_on="employee_id", how="left")
df.join(other=df, left_on="manager_id", right_on="employee_id", how="left")
.select(
exprs=[
pl.col("employee_id"),
Expand Down

0 comments on commit d60cfa1

Please sign in to comment.