Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ jobs:
- name: install-reqs
run: python -m pip install --upgrade tox virtualenv setuptools pip -r requirements-dev.txt
- name: Run pytest
run: pytest tests --cov=dataframe_api_compat --cov=tests --cov-fail-under=100
run: |
pytest tests --cov=dataframe_api_compat/pandas_standard --cov=tests --cov-append --cov-fail-under=50 --cov-report= --library pandas-numpy
pytest tests --cov=dataframe_api_compat/pandas_standard --cov=tests --cov-append --cov-fail-under=50 --cov-report= --library pandas-nullable
pytest tests --cov=dataframe_api_compat/polars_standard --cov=tests --cov-append --cov-fail-under=100 --library polars-lazy
Comment on lines +33 to +35
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more scalable way to run tests. Not all dependencies can be installed in one environment and in the future we will have to use different environments for different implementations.

- name: install type-checking reqs
run: python -m pip install 'git+https://github.com/data-apis/dataframe-api.git#egg=dataframe_api&subdirectory=spec/API_specification' mypy typing-extensions
- name: run mypy
Expand Down
9 changes: 5 additions & 4 deletions tests/column/and_or_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from tests.utils import BaseHandler
from tests.utils import bool_dataframe_1
from tests.utils import compare_column_with_reference


def test_column_and(library: str) -> None:
def test_column_and(library: BaseHandler) -> None:
df = bool_dataframe_1(library, api_version="2023.09-beta")
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand All @@ -14,7 +15,7 @@ def test_column_and(library: str) -> None:
compare_column_with_reference(result.col("result"), expected, dtype=ns.Bool)


def test_column_or(library: str) -> None:
def test_column_or(library: BaseHandler) -> None:
df = bool_dataframe_1(library)
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand All @@ -24,7 +25,7 @@ def test_column_or(library: str) -> None:
compare_column_with_reference(result.col("result"), expected, dtype=ns.Bool)


def test_column_and_with_scalar(library: str) -> None:
def test_column_and_with_scalar(library: BaseHandler) -> None:
df = bool_dataframe_1(library)
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand All @@ -34,7 +35,7 @@ def test_column_and_with_scalar(library: str) -> None:
compare_column_with_reference(result.col("result"), expected, dtype=ns.Bool)


def test_column_or_with_scalar(library: str) -> None:
def test_column_or_with_scalar(library: BaseHandler) -> None:
df = bool_dataframe_1(library)
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand Down
5 changes: 3 additions & 2 deletions tests/column/any_all_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import pytest

from tests.utils import BaseHandler
from tests.utils import bool_dataframe_1


def test_expr_any(library: str) -> None:
def test_expr_any(library: BaseHandler) -> None:
df = bool_dataframe_1(library)
with pytest.raises(RuntimeError):
bool(df.col("a").any())
Expand All @@ -15,7 +16,7 @@ def test_expr_any(library: str) -> None:
assert bool(result.persist())


def test_expr_all(library: str) -> None:
def test_expr_all(library: BaseHandler) -> None:
df = bool_dataframe_1(library).persist()
result = df.col("a").all()
assert not bool(result)
3 changes: 2 additions & 1 deletion tests/column/cast_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from tests.utils import BaseHandler
from tests.utils import compare_dataframe_with_reference
from tests.utils import integer_dataframe_1


def test_cast_integers(library: str) -> None:
def test_cast_integers(library: BaseHandler) -> None:
df = integer_dataframe_1(library)
ns = df.__dataframe_namespace__()
result = df.assign(df.col("a").cast(ns.Int32()))
Expand Down
9 changes: 5 additions & 4 deletions tests/column/col_sorted_indices_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from tests.utils import BaseHandler
from tests.utils import compare_dataframe_with_reference
from tests.utils import integer_dataframe_6


def test_expression_sorted_indices_ascending(library: str) -> None:
def test_expression_sorted_indices_ascending(library: BaseHandler) -> None:
df = integer_dataframe_6(library)
ns = df.__dataframe_namespace__()
col = df.col
Expand All @@ -14,7 +15,7 @@ def test_expression_sorted_indices_ascending(library: str) -> None:
compare_dataframe_with_reference(result, expected, dtype=ns.Int64)


def test_expression_sorted_indices_descending(library: str) -> None:
def test_expression_sorted_indices_descending(library: BaseHandler) -> None:
df = integer_dataframe_6(library)
ns = df.__dataframe_namespace__()
col = df.col
Expand All @@ -24,7 +25,7 @@ def test_expression_sorted_indices_descending(library: str) -> None:
compare_dataframe_with_reference(result, expected, dtype=ns.Int64)


def test_column_sorted_indices_ascending(library: str) -> None:
def test_column_sorted_indices_ascending(library: BaseHandler) -> None:
df = integer_dataframe_6(library)
ns = df.__dataframe_namespace__()
sorted_indices = df.col("b").sorted_indices()
Expand All @@ -33,7 +34,7 @@ def test_column_sorted_indices_ascending(library: str) -> None:
compare_dataframe_with_reference(result, expected, dtype=ns.Int64)


def test_column_sorted_indices_descending(library: str) -> None:
def test_column_sorted_indices_descending(library: BaseHandler) -> None:
df = integer_dataframe_6(library)
ns = df.__dataframe_namespace__()
sorted_indices = df.col("b").sorted_indices(ascending=False)
Expand Down
7 changes: 4 additions & 3 deletions tests/column/col_to_array_object_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import pytest

from tests.utils import BaseHandler
from tests.utils import bool_dataframe_1
from tests.utils import integer_dataframe_1

Expand All @@ -22,21 +23,21 @@
"float64",
],
)
def test_column_to_array_object(library: str, dtype: str) -> None: # noqa: ARG001
def test_column_to_array_object(library: BaseHandler, dtype: str) -> None: # noqa: ARG001
ser = integer_dataframe_1(library).col("a").persist()
result = np.asarray(ser.to_array())
expected = np.array([1, 2, 3], dtype=np.int64)
np.testing.assert_array_equal(result, expected)


def test_column_to_array_object_bool(library: str) -> None:
def test_column_to_array_object_bool(library: BaseHandler) -> None:
df = bool_dataframe_1(library).persist().col("a")
result = np.asarray(df.to_array())
expected = np.array([True, True, False], dtype="bool")
np.testing.assert_array_equal(result, expected)


def test_column_to_array_object_invalid(library: str) -> None:
def test_column_to_array_object_invalid(library: BaseHandler) -> None:
df = bool_dataframe_1(library).col("a")
with pytest.raises(RuntimeError):
_ = np.asarray(df.to_array())
11 changes: 6 additions & 5 deletions tests/column/comparisons_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from tests.utils import BaseHandler
from tests.utils import compare_column_with_reference
from tests.utils import integer_dataframe_1
from tests.utils import integer_dataframe_7
Expand All @@ -28,7 +29,7 @@
],
)
def test_column_comparisons(
library: str,
library: BaseHandler,
comparison: str,
expected_data: list[object],
expected_dtype: str,
Expand All @@ -40,7 +41,7 @@ def test_column_comparisons(
other = df.col("b")
result = df.assign(getattr(ser, comparison)(other).rename("result"))
expected_ns_dtype = getattr(ns, expected_dtype)
if comparison == "__pow__" and library in ("polars", "polars-lazy"):
if comparison == "__pow__" and library.name in ("polars", "polars-lazy"):
# TODO
result = result.cast({"result": ns.Int64()})
expected_ns_dtype = ns.Int64
Expand All @@ -66,7 +67,7 @@ def test_column_comparisons(
],
)
def test_column_comparisons_scalar(
library: str,
library: BaseHandler,
comparison: str,
expected_data: list[object],
expected_dtype: str,
Expand All @@ -78,7 +79,7 @@ def test_column_comparisons_scalar(
other = 3
result = df.assign(getattr(ser, comparison)(other).rename("result"))
expected_ns_dtype = getattr(ns, expected_dtype)
if comparison == "__pow__" and library in ("polars", "polars-lazy"):
if comparison == "__pow__" and library.name in ("polars", "polars-lazy"):
result = result.cast({"result": ns.Int64()})
expected_ns_dtype = ns.Int64
compare_column_with_reference(result.col("result"), expected_data, expected_ns_dtype)
Expand All @@ -93,7 +94,7 @@ def test_column_comparisons_scalar(
],
)
def test_right_column_comparisons(
library: str,
library: BaseHandler,
comparison: str,
expected_data: list[object],
) -> None:
Expand Down
5 changes: 3 additions & 2 deletions tests/column/cross_df_comparisons_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import pytest

from tests.utils import BaseHandler
from tests.utils import integer_dataframe_1
from tests.utils import integer_dataframe_2


def test_invalid_comparisons(library: str) -> None:
def test_invalid_comparisons(library: BaseHandler) -> None:
with pytest.raises(ValueError):
_ = integer_dataframe_1(library).col("a") > integer_dataframe_2(library).col("a")


def test_invalid_comparisons_scalar(library: str) -> None:
def test_invalid_comparisons_scalar(library: BaseHandler) -> None:
with pytest.raises(ValueError):
_ = (
integer_dataframe_1(library).col("a")
Expand Down
5 changes: 3 additions & 2 deletions tests/column/cumulative_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from packaging.version import Version
from packaging.version import parse

from tests.utils import BaseHandler
from tests.utils import compare_column_with_reference
from tests.utils import integer_dataframe_1

Expand All @@ -19,7 +20,7 @@
],
)
def test_cumulative_functions_column(
library: str,
library: BaseHandler,
func: str,
expected_data: list[float],
) -> None:
Expand All @@ -30,7 +31,7 @@ def test_cumulative_functions_column(
result = df.assign(getattr(ser, func)().rename("result"))

if (
parse(pd.__version__) < Version("2.0.0") and library == "pandas-nullable"
parse(pd.__version__) < Version("2.0.0") and library.name == "pandas-nullable"
): # pragma: no cover
# Upstream bug
result = result.cast({"result": ns.Int64()})
Expand Down
5 changes: 3 additions & 2 deletions tests/column/divmod_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from tests.utils import BaseHandler
from tests.utils import compare_column_with_reference
from tests.utils import integer_dataframe_1


def test_expression_divmod(library: str) -> None:
def test_expression_divmod(library: BaseHandler) -> None:
df = integer_dataframe_1(library)
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand All @@ -18,7 +19,7 @@ def test_expression_divmod(library: str) -> None:
compare_column_with_reference(result.col("result"), [1, 2, 3], dtype=ns.Int64)


def test_expression_divmod_with_scalar(library: str) -> None:
def test_expression_divmod_with_scalar(library: BaseHandler) -> None:
df = integer_dataframe_1(library)
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand Down
5 changes: 3 additions & 2 deletions tests/column/fill_nan_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from tests.utils import BaseHandler
from tests.utils import compare_column_with_reference
from tests.utils import nan_dataframe_1


def test_column_fill_nan(library: str) -> None:
def test_column_fill_nan(library: BaseHandler) -> None:
# TODO: test with nullable pandas, check null isn't filled
df = nan_dataframe_1(library)
ns = df.__dataframe_namespace__()
Expand All @@ -14,7 +15,7 @@ def test_column_fill_nan(library: str) -> None:
compare_column_with_reference(result.col("result"), expected, dtype=ns.Float64)


def test_column_fill_nan_with_null(library: str) -> None:
def test_column_fill_nan_with_null(library: BaseHandler) -> None:
# TODO: test with nullable pandas, check null isn't filled
df = nan_dataframe_1(library)
ns = df.__dataframe_namespace__()
Expand Down
13 changes: 7 additions & 6 deletions tests/column/fill_null_test.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from __future__ import annotations

from tests.utils import BaseHandler
from tests.utils import nan_dataframe_1
from tests.utils import null_dataframe_2


def test_fill_null_column(library: str) -> None:
def test_fill_null_column(library: BaseHandler) -> None:
df = null_dataframe_2(library)
ser = df.col("a")
result = df.assign(ser.fill_null(0).rename("result")).col("result")
assert float(result.get_value(2).persist()) == 0.0 # type:ignore[arg-type]
assert float(result.get_value(1).persist()) != 0.0 # type:ignore[arg-type]
assert float(result.get_value(0).persist()) != 0.0 # type:ignore[arg-type]
assert float(result.get_value(2).persist()) == 0.0 # type: ignore[arg-type]
assert float(result.get_value(1).persist()) != 0.0 # type: ignore[arg-type]
assert float(result.get_value(0).persist()) != 0.0 # type: ignore[arg-type]


def test_fill_null_noop_column(library: str) -> None:
def test_fill_null_noop_column(library: BaseHandler) -> None:
df = nan_dataframe_1(library)
ser = df.col("a")
result = df.assign(ser.fill_null(0).rename("result")).persist().col("result")
if library != "pandas-numpy":
if library.name not in ("pandas-numpy",):
# nan should not have changed!
assert float(result.get_value(2)) != float( # type: ignore[arg-type]
result.get_value(2), # type: ignore[arg-type]
Expand Down
5 changes: 3 additions & 2 deletions tests/column/get_rows_by_mask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import pandas as pd

from tests.utils import BaseHandler
from tests.utils import compare_column_with_reference
from tests.utils import integer_dataframe_1


def test_column_filter(library: str) -> None:
def test_column_filter(library: BaseHandler) -> None:
df = integer_dataframe_1(library)
ser = df.col("a")
mask = ser > 1
Expand All @@ -16,7 +17,7 @@ def test_column_filter(library: str) -> None:
pd.testing.assert_series_equal(result_pd, expected)


def test_column_take_by_mask_noop(library: str) -> None:
def test_column_take_by_mask_noop(library: BaseHandler) -> None:
df = integer_dataframe_1(library)
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand Down
3 changes: 2 additions & 1 deletion tests/column/get_rows_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from tests.utils import BaseHandler
from tests.utils import compare_column_with_reference
from tests.utils import integer_dataframe_1


def test_expression_take(library: str) -> None:
def test_expression_take(library: BaseHandler) -> None:
df = integer_dataframe_1(library)
ns = df.__dataframe_namespace__()
ser = df.col("a")
Expand Down
5 changes: 3 additions & 2 deletions tests/column/get_value_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from tests.utils import BaseHandler
from tests.utils import integer_dataframe_1


def test_get_value(library: str) -> None:
def test_get_value(library: BaseHandler) -> None:
result = integer_dataframe_1(library).persist().col("a").get_value(0)
assert int(result) == 1 # type: ignore[call-overload]


def test_mean_scalar(library: str) -> None:
def test_mean_scalar(library: BaseHandler) -> None:
result = integer_dataframe_1(library).persist().col("a").max()
assert int(result) == 3 # type: ignore[call-overload]
Loading