Skip to content

Commit

Permalink
Merge pull request #84 from MarcoGorelli/back-to-1.1.5
Browse files Browse the repository at this point in the history
make pandas>=1.1.5 the minimum requirement
  • Loading branch information
MarcoGorelli authored May 5, 2024
2 parents fcd637f + a9016cd commit df64a55
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/extremes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: install-reqs
run: python -m pip install --upgrade tox virtualenv setuptools pip -r requirements-dev.txt
- name: install-modin
run: python -m pip install pandas==1.2.0 polars==0.20.3
run: python -m pip install pandas==1.1.5 polars==0.20.3
- name: Run pytest
run: pytest tests --cov=narwhals --cov=tests --cov-fail-under=50 --runslow
- name: Run doctests
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
]

[project.optional-dependencies]
pandas = ["pandas>=1.2.0"]
pandas = ["pandas>=1.1.5"]
polars = ["polars>=0.20.3"]

[project.urls]
Expand Down Expand Up @@ -87,7 +87,6 @@ plugins = ["covdefaults"]
exclude_also = [
"> POLARS_VERSION",
"if sys.version_info() <",
'if df_raw is None:',
]

[tool.mypy]
Expand Down
53 changes: 11 additions & 42 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
from tests.utils import compare_dicts

df_pandas = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
df_pandas_nullable = pd.DataFrame(
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
).astype(
{
"a": "Int64",
"b": "Int64",
"z": "Float64",
}
)
if parse_version(pd.__version__) >= parse_version("1.5.0"):
df_pandas_pyarrow = pd.DataFrame(
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
Expand All @@ -35,8 +26,18 @@
"z": "Float64[pyarrow]",
}
)
df_pandas_nullable = pd.DataFrame(
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
).astype(
{
"a": "Int64",
"b": "Int64",
"z": "Float64",
}
)
else: # pragma: no cover
df_pandas_pyarrow = None
df_pandas_pyarrow = df_pandas
df_pandas_nullable = df_pandas
df_polars = pl.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
df_lazy = pl.LazyFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
df_pandas_na = pd.DataFrame({"a": [None, 3, 2], "b": [4, 4, 6], "z": [7.0, None, 9]})
Expand Down Expand Up @@ -64,8 +65,6 @@
[df_pandas, df_polars, df_lazy, df_pandas_nullable, df_pandas_pyarrow],
)
def test_sort(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.sort("a", "b")
result_native = nw.to_native(result)
Expand All @@ -90,8 +89,6 @@ def test_sort(df_raw: Any) -> None:
[df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow],
)
def test_filter(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.filter(nw.col("a") > 1)
result_native = nw.to_native(result)
Expand All @@ -116,8 +113,6 @@ def test_filter_series(df_raw: Any) -> None:
[df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow],
)
def test_add(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.with_columns(
c=nw.col("a") + nw.col("b"),
Expand All @@ -141,8 +136,6 @@ def test_add(df_raw: Any) -> None:
[df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow],
)
def test_double(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.with_columns(nw.all() * 2)
result_native = nw.to_native(result)
Expand All @@ -159,8 +152,6 @@ def test_double(df_raw: Any) -> None:
[df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow],
)
def test_select(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.select("a")
result_native = nw.to_native(result)
Expand All @@ -186,8 +177,6 @@ def test_sumh(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_sumh_literal(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.with_columns(horizonal_sum=nw.sum_horizontal("a", nw.col("b")))
result_native = nw.to_native(result)
Expand All @@ -204,8 +193,6 @@ def test_sumh_literal(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_sum_all(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.select(nw.all().sum())
result_native = nw.to_native(result)
Expand All @@ -217,8 +204,6 @@ def test_sum_all(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_double_selected(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.select(nw.col("a", "b") * 2)
result_native = nw.to_native(result)
Expand All @@ -238,8 +223,6 @@ def test_double_selected(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_rename(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.rename({"a": "x", "b": "y"})
result_native = nw.to_native(result)
Expand All @@ -251,8 +234,6 @@ def test_rename(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_join(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
df_right = df
result = df.join(df_right, left_on=["a", "b"], right_on=["a", "b"], how="inner")
Expand All @@ -279,8 +260,6 @@ def test_join(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_schema(df_raw: Any) -> None:
if df_raw is None:
return
result = nw.LazyFrame(df_raw).schema
expected = {"a": nw.Int64, "b": nw.Int64, "z": nw.Float64}
assert result == expected
Expand All @@ -299,8 +278,6 @@ def test_schema(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_columns(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = df.columns
expected = ["a", "b", "z"]
Expand Down Expand Up @@ -360,8 +337,6 @@ def test_convert_pandas(df_raw: Any) -> None:
r"ignore:np\.find_common_type is deprecated\.:DeprecationWarning"
)
def test_convert_numpy(df_raw: Any) -> None:
if df_raw is None:
return
result = nw.DataFrame(df_raw).to_numpy()
expected = np.array([[1, 3, 2], [4, 4, 6], [7.0, 8, 9]]).T
np.testing.assert_array_equal(result, expected)
Expand Down Expand Up @@ -487,8 +462,6 @@ def test_expr_na(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_head(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = nw.to_native(df.head(2))
expected = {"a": [1, 3], "b": [4, 4], "z": [7.0, 8.0]}
Expand All @@ -502,8 +475,6 @@ def test_head(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_unique(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = nw.to_native(df.unique("b").sort("b"))
expected = {"a": [1, 2], "b": [4, 6], "z": [7.0, 9.0]}
Expand Down Expand Up @@ -594,8 +565,6 @@ def test_to_dict() -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_any_all(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw)
result = nw.to_native(df.select((nw.all() > 1).all()))
expected = {"a": [False], "b": [True], "z": [True]}
Expand Down
28 changes: 16 additions & 12 deletions tests/test_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

import narwhals as nw
from narwhals.utils import parse_version
from tests.utils import compare_dicts

df_pandas = pd.DataFrame(
Expand All @@ -17,18 +18,6 @@
"z": [7.0, 8, 9],
}
)
df_pandas_nullable = pd.DataFrame(
{
"a": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
"b": [4, 4, 6],
"z": [7.0, 8, 9],
}
).astype(
{
"b": "Int64",
"z": "Float64",
}
)
df_polars = pl.DataFrame(
{
"a": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
Expand All @@ -43,6 +32,21 @@
"z": [7.0, 8, 9],
}
)
if parse_version(pd.__version__) >= parse_version("1.2.0"):
df_pandas_nullable = pd.DataFrame(
{
"a": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
"b": [4, 4, 6],
"z": [7.0, 8, 9],
}
).astype(
{
"b": "Int64",
"z": "Float64",
}
)
else: # pragma: no cover
df_pandas_nullable = df_pandas


@pytest.mark.parametrize("df_raw", [df_pandas, df_lazy, df_pandas_nullable])
Expand Down
30 changes: 12 additions & 18 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
from narwhals.utils import parse_version

df_pandas = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
df_pandas_nullable = pd.DataFrame(
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
).astype(
{
"a": "Int64",
"b": "Int64",
"z": "Float64",
}
)
if parse_version(pd.__version__) >= parse_version("1.5.0"):
df_pandas_pyarrow = pd.DataFrame(
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
Expand All @@ -32,8 +23,19 @@
"z": "Float64[pyarrow]",
}
)
df_pandas_nullable = pd.DataFrame(
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
).astype(
{
"a": "Int64",
"b": "Int64",
"z": "Float64",
}
)
else: # pragma: no cover
df_pandas_pyarrow = None
# pyarrow/nullable dtypes not supported so far back
df_pandas_pyarrow = df_pandas
df_pandas_nullable = df_pandas
df_polars = pl.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
df_lazy = pl.LazyFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})

Expand All @@ -42,8 +44,6 @@
"df_raw", [df_pandas, df_polars, df_pandas_nullable, df_pandas_pyarrow]
)
def test_len(df_raw: Any) -> None:
if df_raw is None:
return
result = len(nw.Series(df_raw["a"]))
assert result == 3
result = len(nw.LazyFrame(df_raw).collect()["a"])
Expand Down Expand Up @@ -87,8 +87,6 @@ def test_gt(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_dtype(df_raw: Any) -> None:
if df_raw is None:
return
result = nw.LazyFrame(df_raw).collect()["a"].dtype
assert result == nw.Int64
assert result.is_numeric()
Expand All @@ -98,8 +96,6 @@ def test_dtype(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_reductions(df_raw: Any) -> None:
if df_raw is None:
return
s = nw.LazyFrame(df_raw).collect()["a"]
assert s.mean() == 2.0
assert s.std() == 1.0
Expand All @@ -121,8 +117,6 @@ def test_reductions(df_raw: Any) -> None:
"df_raw", [df_pandas, df_lazy, df_pandas_nullable, df_pandas_pyarrow]
)
def test_boolean_reductions(df_raw: Any) -> None:
if df_raw is None:
return
df = nw.LazyFrame(df_raw).select(nw.col("a") > 1)
assert not df.collect()["a"].all()
assert df.collect()["a"].any()
Expand Down

0 comments on commit df64a55

Please sign in to comment.