Skip to content

Commit

Permalink
Upgrade multimethod to 1.12 (#1803)
Browse files Browse the repository at this point in the history
* deps: Bump multimethod requirement to 1.12

Signed-off-by: Joshua Skrzypek <[email protected]>

* Swap out @overload for @multidispatch.

This removes the deprecated @overload decorator and replaces it with the
@multidispatch decorator, using multimethod.parametric.

Signed-off-by: Joshua Skrzypek <[email protected]>

* lint: Fix lint errors

Signed-off-by: Joshua Skrzypek <[email protected]>

* refactor: Pull out parametric requirement

Instead of using multimethod.parametric, we can just use typing Unions,
because the predicates that were passed to parametric are just calling
isinstance on the type tuples.

Signed-off-by: Joshua Skrzypek <[email protected]>

* Unpin multimethod after taking out parametric dependency.

Signed-off-by: Joshua Skrzypek <[email protected]>

* Appease mypy lint checker

There would be cleaner ways to do this, but not in python 3.8 (i.e. no
explicit types.UnionType, etc.).

Signed-off-by: Joshua Skrzypek <[email protected]>

---------

Signed-off-by: Joshua Skrzypek <[email protected]>
  • Loading branch information
jskrzypek authored Sep 21, 2024
1 parent ba6cd87 commit f62872b
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 118 deletions.
2 changes: 1 addition & 1 deletion ci/requirements-py3.10-pandas1.5.3-pydantic1.10.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mdurl==0.1.2
modin==0.22.3
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.10-pandas1.5.3-pydantic2.3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mdurl==0.1.2
modin==0.22.3
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.10-pandas2.2.2-pydantic1.10.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.10-pandas2.2.2-pydantic2.3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.11-pandas1.5.3-pydantic1.10.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mdurl==0.1.2
modin==0.22.3
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.11-pandas1.5.3-pydantic2.3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mdurl==0.1.2
modin==0.22.3
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.11-pandas2.2.2-pydantic1.10.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.11-pandas2.2.2-pydantic2.3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.9-pandas1.5.3-pydantic1.10.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mdurl==0.1.2
modin==0.22.3
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.9-pandas1.5.3-pydantic2.3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mdurl==0.1.2
modin==0.22.3
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.9-pandas2.2.2-pydantic1.10.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.9-pandas2.2.2-pydantic2.3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion dev/requirements-3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion dev/requirements-3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
2 changes: 1 addition & 1 deletion dev/requirements-3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mdurl==0.1.2
modin==0.31.0
more-itertools==10.4.0
msgpack==1.0.8
multimethod==1.10
multimethod==1.12
mypy==1.10.0
mypy-extensions==1.0.0
myst-nb==1.1.1
Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ dependencies:
- pyyaml >=5.1
- typing_inspect >= 0.6.0
- typing_extensions >= 3.7.4.3
- frictionless <= 4.40.8 # v5.* introduces breaking changes
- frictionless <= 4.40.8 # v5.* introduces breaking changes
- pyarrow
- pydantic
- multimethod <= 1.10.0
- multimethod

# mypy extra
- pandas-stubs
Expand Down
60 changes: 45 additions & 15 deletions pandera/api/pandas/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,35 @@
def supported_types() -> SupportedTypes:
"""Get the types supported by pandera schemas."""
# pylint: disable=import-outside-toplevel
table_types = [pd.DataFrame]
field_types = [pd.Series]
index_types = [pd.Index]
multiindex_types = [pd.MultiIndex]
table_types: Tuple[type, ...] = (pd.DataFrame,)
field_types: Tuple[type, ...] = (pd.Series,)
index_types: Tuple[type, ...] = (pd.Index,)
multiindex_types: Tuple[type, ...] = (pd.MultiIndex,)

try:
import pyspark.pandas as ps

table_types.append(ps.DataFrame)
field_types.append(ps.Series)
index_types.append(ps.Index)
multiindex_types.append(ps.MultiIndex)
table_types += (ps.DataFrame,)
field_types += (ps.Series,)
index_types += (ps.Index,)
multiindex_types += (ps.MultiIndex,)
except ImportError:
pass
try: # pragma: no cover
import modin.pandas as mpd

table_types.append(mpd.DataFrame)
field_types.append(mpd.Series)
index_types.append(mpd.Index)
multiindex_types.append(mpd.MultiIndex)
table_types += (mpd.DataFrame,)
field_types += (mpd.Series,)
index_types += (mpd.Index,)
multiindex_types += (mpd.MultiIndex,)
except ImportError:
pass
try:
import dask.dataframe as dd

table_types.append(dd.DataFrame)
field_types.append(dd.Series)
index_types.append(dd.Index)
table_types += (dd.DataFrame,)
field_types += (dd.Series,)
index_types += (dd.Index,)
except ImportError:
pass

Expand All @@ -72,6 +72,36 @@ def supported_types() -> SupportedTypes:
)


def supported_type_unions(attribute: str):
"""Get the type unions for a given attribute."""
if attribute == "table_types":
return Union[tuple(supported_types().table_types)]
if attribute == "field_types":
return Union[tuple(supported_types().field_types)]
if attribute == "index_types":
return Union[tuple(supported_types().index_types)]
if attribute == "multiindex_types":
return Union[tuple(supported_types().multiindex_types)]
if attribute == "table_or_field_types":
return Union[
tuple(
(
*supported_types().table_types,
*supported_types().field_types,
)
)
]
raise ValueError(f"invalid attribute {attribute}")


Table = supported_type_unions("table_types")
Field = supported_type_unions("field_types")
Index = supported_type_unions("index_types")
Multiindex = supported_type_unions("multiindex_types")
TableOrField = supported_type_unions("table_or_field_types")
Bool = Union[bool, np.bool_]


def is_table(obj):
"""Verifies whether an object is table-like.
Expand Down
8 changes: 8 additions & 0 deletions pandera/api/polars/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ class CheckResult(NamedTuple):
type,
pl.datatypes.classes.DataTypeClass,
]


def is_bool(x):
"""Verifies whether an object is a boolean type."""
return isinstance(x, (bool, pl.Boolean))


Bool = Union[bool, pl.Boolean]
Loading

0 comments on commit f62872b

Please sign in to comment.