-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from DeaMariaLeon/test
Test: Trying to use hypothesis for Expr.is_null()
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pre-commit | |
pyarrow | ||
pytest | ||
pytest-cov | ||
hypothesis |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())), | ||
) |