From 9d1bde27eb20b60563d93bce9992cba3ad1371f2 Mon Sep 17 00:00:00 2001 From: SecretLake Date: Fri, 21 Apr 2023 10:15:19 +0000 Subject: [PATCH 1/4] Test dir of pandas.api.* --- pandas/tests/api/test_api.py | 89 +++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index c2e89a2db12ee..f391e94895910 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -6,6 +6,10 @@ from pandas import api import pandas._testing as tm from pandas.api import typing as api_typing +from pandas.api import types as api_types +from pandas.api import interchange as api_interchange +from pandas.api import indexers as api_indexers +from pandas.api import extensions as api_extensions class Base: @@ -17,10 +21,12 @@ def check(self, namespace, expected, ignored=None): result = sorted( f for f in dir(namespace) if not f.startswith("__") and f != "annotations" ) + if ignored is not None: result = sorted(set(result) - set(ignored)) expected = sorted(expected) + tm.assert_almost_equal(result, expected) @@ -256,13 +262,94 @@ class TestApi(Base): "TimeGrouper", "Window", ] + allowed_api_types = [ + "is_any_real_numeric_dtype", + "is_array_like", + "is_bool", + "is_bool_dtype", + "is_categorical_dtype", + "is_complex", + "is_complex_dtype", + "is_datetime64_any_dtype", + "is_datetime64_dtype", + "is_datetime64_ns_dtype", + "is_datetime64tz_dtype", + "is_dict_like", + "is_dtype_equal", + "is_extension_array_dtype", + "is_file_like", + "is_float", + "is_float_dtype", + "is_hashable", + "is_int64_dtype", + "is_integer", + "is_integer_dtype", + "is_interval", + "is_interval_dtype", + "is_iterator", + "is_list_like", + "is_named_tuple", + "is_number", + "is_numeric_dtype", + "is_object_dtype", + "is_period_dtype", + "is_re", + "is_re_compilable", + "is_scalar", + "is_signed_integer_dtype", + "is_sparse", + "is_string_dtype", + "is_timedelta64_dtype", + "is_timedelta64_ns_dtype", + "is_unsigned_integer_dtype", + "pandas_dtype", + "infer_dtype", + "union_categoricals", + "CategoricalDtype", + "DatetimeTZDtype", + "IntervalDtype", + "PeriodDtype", + ] + allowed_api_interchange = [ + "from_dataframe", + "DataFrame" + ] + allowed_api_indexers = [ + "check_array_indexer", + "BaseIndexer", + "FixedForwardWindowIndexer", + "VariableOffsetWindowIndexer", + ] + allowed_api_extensions = [ + "no_default", + "ExtensionDtype", + "register_extension_dtype", + "register_dataframe_accessor", + "register_index_accessor", + "register_series_accessor", + "take", + "ExtensionArray", + "ExtensionScalarOpsMixin", + ] + def test_api(self): self.check(api, self.allowed) def test_api_typing(self): self.check(api_typing, self.allowed_typing) - + + def test_api_types(self): + self.check(api_types, self.allowed_api_types) + + def test_api_interchange(self): + self.check(api_interchange, self.allowed_api_interchange) + + def test_api_indexers(self): + self.check(api_indexers, self.allowed_api_indexers) + + def test_api_extensions(self): + self.check(api_extensions, self.allowed_api_extensions) class TestTesting(Base): funcs = [ From 6d779dabd0196a36061e7f306ab05741d6af102a Mon Sep 17 00:00:00 2001 From: SecretLake Date: Fri, 21 Apr 2023 10:17:21 +0000 Subject: [PATCH 2/4] Fix pre-commit changes --- pandas/tests/api/test_api.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index f391e94895910..6cf80d23c92d0 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -5,11 +5,13 @@ import pandas as pd from pandas import api import pandas._testing as tm -from pandas.api import typing as api_typing -from pandas.api import types as api_types -from pandas.api import interchange as api_interchange -from pandas.api import indexers as api_indexers -from pandas.api import extensions as api_extensions +from pandas.api import ( + extensions as api_extensions, + indexers as api_indexers, + interchange as api_interchange, + types as api_types, + typing as api_typing, +) class Base: @@ -310,10 +312,7 @@ class TestApi(Base): "IntervalDtype", "PeriodDtype", ] - allowed_api_interchange = [ - "from_dataframe", - "DataFrame" - ] + allowed_api_interchange = ["from_dataframe", "DataFrame"] allowed_api_indexers = [ "check_array_indexer", "BaseIndexer", @@ -332,25 +331,25 @@ class TestApi(Base): "ExtensionScalarOpsMixin", ] - def test_api(self): self.check(api, self.allowed) def test_api_typing(self): self.check(api_typing, self.allowed_typing) - + def test_api_types(self): self.check(api_types, self.allowed_api_types) def test_api_interchange(self): self.check(api_interchange, self.allowed_api_interchange) - + def test_api_indexers(self): self.check(api_indexers, self.allowed_api_indexers) - + def test_api_extensions(self): self.check(api_extensions, self.allowed_api_extensions) + class TestTesting(Base): funcs = [ "assert_frame_equal", From cbd77377a3e453e6bab38a8f817157a2c2f3ade0 Mon Sep 17 00:00:00 2001 From: SecretLake Date: Fri, 21 Apr 2023 10:37:46 +0000 Subject: [PATCH 3/4] Fix pre-commit errors --- pandas/tests/api/test_api.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 6cf80d23c92d0..e57b1e8d8739f 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -245,8 +245,14 @@ def test_depr(self): class TestApi(Base): - allowed = ["types", "extensions", "indexers", "interchange", "typing"] - allowed_typing = [ + allowed_api_dirs: list[str] = [ + "types", + "extensions", + "indexers", + "interchange", + "typing", + ] + allowed_typing: list[str] = [ "DataFrameGroupBy", "DatetimeIndexResamplerGroupby", "Expanding", @@ -264,7 +270,7 @@ class TestApi(Base): "TimeGrouper", "Window", ] - allowed_api_types = [ + allowed_api_types: list[str] = [ "is_any_real_numeric_dtype", "is_array_like", "is_bool", @@ -312,14 +318,14 @@ class TestApi(Base): "IntervalDtype", "PeriodDtype", ] - allowed_api_interchange = ["from_dataframe", "DataFrame"] - allowed_api_indexers = [ + allowed_api_interchange: list[str] = ["from_dataframe", "DataFrame"] + allowed_api_indexers: list[str] = [ "check_array_indexer", "BaseIndexer", "FixedForwardWindowIndexer", "VariableOffsetWindowIndexer", ] - allowed_api_extensions = [ + allowed_api_extensions: list[str] = [ "no_default", "ExtensionDtype", "register_extension_dtype", @@ -331,22 +337,22 @@ class TestApi(Base): "ExtensionScalarOpsMixin", ] - def test_api(self): - self.check(api, self.allowed) + def test_api(self) -> None: + self.check(api, self.allowed_api_dirs) - def test_api_typing(self): + def test_api_typing(self) -> None: self.check(api_typing, self.allowed_typing) - def test_api_types(self): + def test_api_types(self) -> None: self.check(api_types, self.allowed_api_types) - def test_api_interchange(self): + def test_api_interchange(self) -> None: self.check(api_interchange, self.allowed_api_interchange) - def test_api_indexers(self): + def test_api_indexers(self) -> None: self.check(api_indexers, self.allowed_api_indexers) - def test_api_extensions(self): + def test_api_extensions(self) -> None: self.check(api_extensions, self.allowed_api_extensions) From a24912173dad8a4eba660094e4dcc744289e188b Mon Sep 17 00:00:00 2001 From: SecretLake Date: Sat, 22 Apr 2023 18:14:42 +0000 Subject: [PATCH 4/4] PR feedback --- pandas/tests/api/test_api.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index e57b1e8d8739f..73713de08473b 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -23,12 +23,10 @@ def check(self, namespace, expected, ignored=None): result = sorted( f for f in dir(namespace) if not f.startswith("__") and f != "annotations" ) - if ignored is not None: result = sorted(set(result) - set(ignored)) expected = sorted(expected) - tm.assert_almost_equal(result, expected) @@ -245,14 +243,14 @@ def test_depr(self): class TestApi(Base): - allowed_api_dirs: list[str] = [ + allowed_api_dirs = [ "types", "extensions", "indexers", "interchange", "typing", ] - allowed_typing: list[str] = [ + allowed_typing = [ "DataFrameGroupBy", "DatetimeIndexResamplerGroupby", "Expanding", @@ -270,7 +268,7 @@ class TestApi(Base): "TimeGrouper", "Window", ] - allowed_api_types: list[str] = [ + allowed_api_types = [ "is_any_real_numeric_dtype", "is_array_like", "is_bool", @@ -318,14 +316,14 @@ class TestApi(Base): "IntervalDtype", "PeriodDtype", ] - allowed_api_interchange: list[str] = ["from_dataframe", "DataFrame"] - allowed_api_indexers: list[str] = [ + allowed_api_interchange = ["from_dataframe", "DataFrame"] + allowed_api_indexers = [ "check_array_indexer", "BaseIndexer", "FixedForwardWindowIndexer", "VariableOffsetWindowIndexer", ] - allowed_api_extensions: list[str] = [ + allowed_api_extensions = [ "no_default", "ExtensionDtype", "register_extension_dtype", @@ -337,22 +335,22 @@ class TestApi(Base): "ExtensionScalarOpsMixin", ] - def test_api(self) -> None: + def test_api(self): self.check(api, self.allowed_api_dirs) - def test_api_typing(self) -> None: + def test_api_typing(self): self.check(api_typing, self.allowed_typing) - def test_api_types(self) -> None: + def test_api_types(self): self.check(api_types, self.allowed_api_types) - def test_api_interchange(self) -> None: + def test_api_interchange(self): self.check(api_interchange, self.allowed_api_interchange) - def test_api_indexers(self) -> None: + def test_api_indexers(self): self.check(api_indexers, self.allowed_api_indexers) - def test_api_extensions(self) -> None: + def test_api_extensions(self): self.check(api_extensions, self.allowed_api_extensions)