Skip to content

Commit a9879b4

Browse files
authored
test: refactor arithmetic floordiv and mod (#2702)
* refactor arithmetic floordiv and mod tests * skip modin for refactored tests
1 parent 367acde commit a9879b4

File tree

1 file changed

+11
-99
lines changed

1 file changed

+11
-99
lines changed

tests/expr_and_series/arithmetic_test.py

Lines changed: 11 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -157,65 +157,16 @@ def test_truediv_same_dims(
157157
assert_equal_data({"a": result}, {"a": [2, 1, 1 / 3]})
158158

159159

160-
@pytest.mark.slow
161160
@given(left=st.integers(-100, 100), right=st.integers(-100, 100))
162161
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
163-
def test_floordiv_pandas(left: int, right: int) -> None:
164-
pytest.importorskip("pandas")
165-
import pandas as pd
166-
167-
# hypothesis complains if we add `constructor` as an argument, so this
168-
# test is a bit manual unfortunately
169-
assume(right != 0)
170-
expected = {"a": [left // right]}
171-
result: nw.DataFrame[Any] = nw.from_native(
172-
pd.DataFrame({"a": [left]}), eager_only=True
173-
).select(nw.col("a") // right)
174-
assert_equal_data(result, expected)
175-
if PANDAS_VERSION < (2, 2): # pragma: no cover
176-
# Bug in old version of pandas
177-
pass
178-
else:
179-
result = nw.from_native(
180-
pd.DataFrame({"a": [left]}).convert_dtypes(dtype_backend="pyarrow"),
181-
eager_only=True,
182-
).select(nw.col("a") // right)
183-
assert_equal_data(result, expected)
184-
result = nw.from_native(
185-
pd.DataFrame({"a": [left]}).convert_dtypes(), eager_only=True
186-
).select(nw.col("a") // right)
187-
assert_equal_data(result, expected)
188-
189-
190162
@pytest.mark.slow
191-
@given(left=st.integers(-100, 100), right=st.integers(-100, 100))
192-
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
193-
def test_floordiv_polars(left: int, right: int) -> None:
194-
pytest.importorskip("polars")
195-
import polars as pl
196-
197-
# hypothesis complains if we add `constructor` as an argument, so this
198-
# test is a bit manual unfortunately
199-
assume(right != 0)
200-
expected = {"a": [left // right]}
201-
result = nw.from_native(pl.DataFrame({"a": [left]}), eager_only=True).select(
202-
nw.col("a") // right
203-
)
204-
assert_equal_data(result, expected)
205-
206-
207-
@pytest.mark.slow
208-
@given(left=st.integers(-100, 100), right=st.integers(-100, 100))
209-
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
210-
def test_floordiv_pyarrow(left: int, right: int) -> None:
211-
pytest.importorskip("pyarrow")
212-
import pyarrow as pa
213-
214-
# hypothesis complains if we add `constructor` as an argument, so this
215-
# test is a bit manual unfortunately
163+
def test_floordiv(constructor_eager: ConstructorEager, *, left: int, right: int) -> None:
164+
if any(x in str(constructor_eager) for x in ["modin", "cudf"]):
165+
# modin & cudf are too slow here
166+
pytest.skip()
216167
assume(right != 0)
217168
expected = {"a": [left // right]}
218-
result = nw.from_native(pa.table({"a": [left]}), eager_only=True).select(
169+
result = nw.from_native(constructor_eager({"a": [left]}), eager_only=True).select(
219170
nw.col("a") // right
220171
)
221172
assert_equal_data(result, expected)
@@ -224,53 +175,14 @@ def test_floordiv_pyarrow(left: int, right: int) -> None:
224175
@pytest.mark.slow
225176
@given(left=st.integers(-100, 100), right=st.integers(-100, 100))
226177
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
227-
def test_mod_pandas(left: int, right: int) -> None:
228-
pytest.importorskip("pandas")
229-
import pandas as pd
230-
231-
# hypothesis complains if we add `constructor` as an argument, so this
232-
# test is a bit manual unfortunately
233-
assume(right != 0)
234-
expected = {"a": [left % right]}
235-
result: nw.DataFrame[Any] = nw.from_native(
236-
pd.DataFrame({"a": [left]}), eager_only=True
237-
).select(nw.col("a") % right)
238-
assert_equal_data(result, expected)
239-
result = nw.from_native(
240-
pd.DataFrame({"a": [left]}).convert_dtypes(), eager_only=True
241-
).select(nw.col("a") % right)
242-
assert_equal_data(result, expected)
243-
244-
245-
@pytest.mark.slow
246-
@given(left=st.integers(-100, 100), right=st.integers(-100, 100))
247-
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
248-
def test_mod_polars(left: int, right: int) -> None:
249-
pytest.importorskip("polars")
250-
import polars as pl
251-
252-
# hypothesis complains if we add `constructor` as an argument, so this
253-
# test is a bit manual unfortunately
254-
assume(right != 0)
255-
expected = {"a": [left % right]}
256-
result = nw.from_native(pl.DataFrame({"a": [left]}), eager_only=True).select(
257-
nw.col("a") % right
258-
)
259-
assert_equal_data(result, expected)
260-
261-
262-
@pytest.mark.slow
263-
@given(left=st.integers(-100, 100), right=st.integers(-100, 100))
264-
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
265-
def test_mod_pyarrow(left: int, right: int) -> None:
266-
pytest.importorskip("pyarrow")
267-
import pyarrow as pa
268-
269-
# hypothesis complains if we add `constructor` as an argument, so this
270-
# test is a bit manual unfortunately
178+
def test_mod(constructor_eager: ConstructorEager, *, left: int, right: int) -> None:
179+
if any(x in str(constructor_eager) for x in ["pandas_pyarrow", "modin", "cudf"]):
180+
# pandas[pyarrow] does not implement mod
181+
# modin & cudf are too slow here
182+
pytest.skip()
271183
assume(right != 0)
272184
expected = {"a": [left % right]}
273-
result = nw.from_native(pa.table({"a": [left]}), eager_only=True).select(
185+
result = nw.from_native(constructor_eager({"a": [left]}), eager_only=True).select(
274186
nw.col("a") % right
275187
)
276188
assert_equal_data(result, expected)

0 commit comments

Comments
 (0)