Skip to content

Commit

Permalink
Merge pull request #37 from DeaMariaLeon/test
Browse files Browse the repository at this point in the history
Test: Trying to use hypothesis for Expr.is_null()
  • Loading branch information
MarcoGorelli authored Apr 8, 2024
2 parents 920eac6 + c73c5e3 commit 586d5b0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pre-commit
pyarrow
pytest
pytest-cov
hypothesis
Empty file added tests/hypothesis/__init__.py
Empty file.
50 changes: 50 additions & 0 deletions tests/hypothesis/test_basic_arithmetic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations

import pandas as pd
import polars as pl
from hypothesis import given
from hypothesis import strategies as st
from numpy.testing import assert_allclose

import narwhals as nw


@given(
st.lists(
st.integers(min_value=-9223372036854775807, max_value=9223372036854775807),
min_size=3,
max_size=3,
),
st.lists(
st.floats(min_value=-9223372036854775807.0, max_value=9223372036854775807.0),
min_size=3,
max_size=3,
),
) # type: ignore[misc]
def test_mean(
integer: st.SearchStrategy[list[int]],
floats: st.SearchStrategy[float],
) -> None:
df_pandas = pd.DataFrame(
{
"integer": integer,
"floats": floats,
}
)
df_polars = pl.DataFrame(
{
"integer": integer,
"floats": floats,
},
)
df_nw1 = nw.DataFrame(df_pandas)
df_nw2 = nw.DataFrame(df_polars)

assert_allclose(
nw.to_native(df_nw1.select(nw.col("integer").mean())),
nw.to_native(df_nw2.select(nw.col("integer").mean())),
)
assert_allclose(
nw.to_native(df_nw1.select(nw.col("floats").mean())),
nw.to_native(df_nw2.select(nw.col("floats").mean())),
)

0 comments on commit 586d5b0

Please sign in to comment.