From 2983bf5529a9bf9fed37eedb73cdfb50735d7f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Tue, 21 Sep 2021 21:39:37 -0400 Subject: [PATCH 01/10] TYP: redundant imports for public API --- pandas/__init__.py | 215 +++++++++++++++++++++++---------------------- 1 file changed, 109 insertions(+), 106 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 294b092e33c58..56cccd73a7c18 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -31,13 +31,16 @@ "'python setup.py build_ext --force' to build the C extensions first." ) from e +# Use redundant imports (X as X) for type checkers to know what is part of the +# public API. Pandas is not (yet) a py.typed library: the public API is determined +# based on the documenation. from pandas._config import ( - get_option, - set_option, - reset_option, - describe_option, - option_context, - options, + get_option as get_option, + set_option as set_option, + reset_option as reset_option, + describe_option as describe_option, + option_context as option_context, + options as options, ) # let init-time option registration happen @@ -45,136 +48,136 @@ from pandas.core.api import ( # dtype - Int8Dtype, - Int16Dtype, - Int32Dtype, - Int64Dtype, - UInt8Dtype, - UInt16Dtype, - UInt32Dtype, - UInt64Dtype, - Float32Dtype, - Float64Dtype, - CategoricalDtype, - PeriodDtype, - IntervalDtype, - DatetimeTZDtype, - StringDtype, - BooleanDtype, + Int8Dtype as Int8Dtype, + Int16Dtype as Int16Dtype, + Int32Dtype as Int32Dtype, + Int64Dtype as Int64Dtype, + UInt8Dtype as UInt8Dtype, + UInt16Dtype as UInt16Dtype, + UInt32Dtype as UInt32Dtype, + UInt64Dtype as UInt64Dtype, + Float32Dtype as Float32Dtype, + Float64Dtype as Float64Dtype, + CategoricalDtype as CategoricalDtype, + PeriodDtype as PeriodDtype, + IntervalDtype as IntervalDtype, + DatetimeTZDtype as DatetimeTZDtype, + StringDtype as StringDtype, + BooleanDtype as BooleanDtype, # missing - NA, - isna, - isnull, - notna, - notnull, + NA as NA, + isna as isna, + isnull as isnull, + notna as notna, + notnull as notnull, # indexes - Index, - CategoricalIndex, - RangeIndex, - NumericIndex, - MultiIndex, - IntervalIndex, - TimedeltaIndex, - DatetimeIndex, - PeriodIndex, - IndexSlice, + Index as Index, + CategoricalIndex as CategoricalIndex, + RangeIndex as RangeIndex, + NumericIndex as NumericIndex, + MultiIndex as MultiIndex, + IntervalIndex as IntervalIndex, + TimedeltaIndex as TimedeltaIndex, + DatetimeIndex as DatetimeIndex, + PeriodIndex as PeriodIndex, + IndexSlice as IndexSlice, # tseries - NaT, - Period, - period_range, - Timedelta, - timedelta_range, - Timestamp, - date_range, - bdate_range, - Interval, - interval_range, - DateOffset, + NaT as NaT, + Period as Period, + period_range as period_range, + Timedelta as Timedelta, + timedelta_range as timedelta_range, + Timestamp as Timestamp, + date_range as date_range, + bdate_range as bdate_range, + Interval as Interval, + interval_range as interval_range, + DateOffset as DateOffset, # conversion - to_numeric, - to_datetime, - to_timedelta, + to_numeric as to_numeric, + to_datetime as to_datetime, + to_timedelta as to_timedelta, # misc - Flags, - Grouper, - factorize, - unique, - value_counts, - NamedAgg, - array, - Categorical, - set_eng_float_format, - Series, - DataFrame, + Flags as Flags, + Grouper as Grouper, + factorize as factorize, + unique as unique, + value_counts as value_counts, + NamedAgg as NamedAgg, + array as array, + Categorical as Categorical, + set_eng_float_format as set_eng_float_format, + Series as Series, + DataFrame as DataFrame, ) -from pandas.core.arrays.sparse import SparseDtype +from pandas.core.arrays.sparse import SparseDtype as SparseDtype -from pandas.tseries.api import infer_freq -from pandas.tseries import offsets +from pandas.tseries.api import infer_freq as infer_freq +from pandas.tseries import offsets as offsets -from pandas.core.computation.api import eval +from pandas.core.computation.api import eval as eval from pandas.core.reshape.api import ( - concat, - lreshape, - melt, - wide_to_long, - merge, - merge_asof, - merge_ordered, - crosstab, - pivot, - pivot_table, - get_dummies, - cut, - qcut, + concat as concat, + lreshape as lreshape, + melt as melt, + wide_to_long as wide_to_long, + merge as merge, + merge_asof as merge_asof, + merge_ordered as merge_ordered, + crosstab as crosstab, + pivot as pivot, + pivot_table as pivot_table, + get_dummies as get_dummies, + cut as cut, + qcut as qcut, ) import pandas.api -from pandas.util._print_versions import show_versions +from pandas.util._print_versions import show_versions as show_versions from pandas.io.api import ( # excel - ExcelFile, - ExcelWriter, - read_excel, + ExcelFile as ExcelFile, + ExcelWriter as ExcelWriter, + read_excel as read_excel, # parsers - read_csv, - read_fwf, - read_table, + read_csv as read_csv, + read_fwf as read_fwf, + read_table as read_table, # pickle - read_pickle, - to_pickle, + read_pickle as read_pickle, + to_pickle as to_pickle, # pytables - HDFStore, - read_hdf, + HDFStore as HDFStore, + read_hdf as read_hdf, # sql - read_sql, - read_sql_query, - read_sql_table, + read_sql as read_sql, + read_sql_query as read_sql_query, + read_sql_table as read_sql_table, # misc - read_clipboard, - read_parquet, - read_orc, - read_feather, - read_gbq, - read_html, - read_xml, - read_json, - read_stata, - read_sas, - read_spss, + read_clipboard as read_clipboard, + read_parquet as read_parquet, + read_orc as read_orc, + read_feather as read_feather, + read_gbq as read_gbq, + read_html as read_html, + read_xml as read_xml, + read_json as read_json, + read_stata as read_stata, + read_sas as read_sas, + read_spss as read_spss, ) from pandas.io.json import _json_normalize as json_normalize -from pandas.util._tester import test +from pandas.util._tester import test as test import pandas.testing import pandas.arrays # use the closest tagged version if possible -from pandas._version import get_versions +from pandas._version import get_versions as get_versions v = get_versions() __version__ = v.get("closest-tag", v["version"]) From 01818da82efbab9438a2c08d1bb34c1edbdd9e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Tue, 21 Sep 2021 21:55:21 -0400 Subject: [PATCH 02/10] typo --- pandas/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 56cccd73a7c18..248fb9b119e7f 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -33,7 +33,7 @@ # Use redundant imports (X as X) for type checkers to know what is part of the # public API. Pandas is not (yet) a py.typed library: the public API is determined -# based on the documenation. +# based on the documentation. from pandas._config import ( get_option as get_option, set_option as set_option, From 1bc208a06d31e6633532056c142dc202c715291f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Wed, 22 Sep 2021 17:44:06 -0400 Subject: [PATCH 03/10] use __all__ --- pandas/__init__.py | 337 ++++++++++++++++++++++++++++++--------------- 1 file changed, 224 insertions(+), 113 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 248fb9b119e7f..e4fc9195cdccb 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -31,16 +31,13 @@ "'python setup.py build_ext --force' to build the C extensions first." ) from e -# Use redundant imports (X as X) for type checkers to know what is part of the -# public API. Pandas is not (yet) a py.typed library: the public API is determined -# based on the documentation. from pandas._config import ( - get_option as get_option, - set_option as set_option, - reset_option as reset_option, - describe_option as describe_option, - option_context as option_context, - options as options, + get_option, + set_option, + reset_option, + describe_option, + option_context, + options, ) # let init-time option registration happen @@ -48,143 +45,142 @@ from pandas.core.api import ( # dtype - Int8Dtype as Int8Dtype, - Int16Dtype as Int16Dtype, - Int32Dtype as Int32Dtype, - Int64Dtype as Int64Dtype, - UInt8Dtype as UInt8Dtype, - UInt16Dtype as UInt16Dtype, - UInt32Dtype as UInt32Dtype, - UInt64Dtype as UInt64Dtype, - Float32Dtype as Float32Dtype, - Float64Dtype as Float64Dtype, - CategoricalDtype as CategoricalDtype, - PeriodDtype as PeriodDtype, - IntervalDtype as IntervalDtype, - DatetimeTZDtype as DatetimeTZDtype, - StringDtype as StringDtype, - BooleanDtype as BooleanDtype, + Int8Dtype, + Int16Dtype, + Int32Dtype, + Int64Dtype, + UInt8Dtype, + UInt16Dtype, + UInt32Dtype, + UInt64Dtype, + Float32Dtype, + Float64Dtype, + CategoricalDtype, + PeriodDtype, + IntervalDtype, + DatetimeTZDtype, + StringDtype, + BooleanDtype, # missing - NA as NA, - isna as isna, - isnull as isnull, - notna as notna, - notnull as notnull, + NA, + isna, + isnull, + notna, + notnull, # indexes - Index as Index, - CategoricalIndex as CategoricalIndex, - RangeIndex as RangeIndex, - NumericIndex as NumericIndex, - MultiIndex as MultiIndex, - IntervalIndex as IntervalIndex, - TimedeltaIndex as TimedeltaIndex, - DatetimeIndex as DatetimeIndex, - PeriodIndex as PeriodIndex, - IndexSlice as IndexSlice, + Index, + CategoricalIndex, + RangeIndex, + NumericIndex, + MultiIndex, + IntervalIndex, + TimedeltaIndex, + DatetimeIndex, + PeriodIndex, + IndexSlice, # tseries - NaT as NaT, - Period as Period, - period_range as period_range, - Timedelta as Timedelta, - timedelta_range as timedelta_range, - Timestamp as Timestamp, - date_range as date_range, - bdate_range as bdate_range, - Interval as Interval, - interval_range as interval_range, - DateOffset as DateOffset, + NaT, + Period, + period_range, + Timedelta, + timedelta_range, + Timestamp, + date_range, + bdate_range, + Interval, + interval_range, + DateOffset, # conversion - to_numeric as to_numeric, - to_datetime as to_datetime, - to_timedelta as to_timedelta, + to_numeric, + to_datetime, + to_timedelta, # misc - Flags as Flags, - Grouper as Grouper, - factorize as factorize, - unique as unique, - value_counts as value_counts, - NamedAgg as NamedAgg, - array as array, - Categorical as Categorical, - set_eng_float_format as set_eng_float_format, - Series as Series, - DataFrame as DataFrame, + Flags, + Grouper, + factorize, + unique, + value_counts, + NamedAgg, + array, + Categorical, + set_eng_float_format, + Series, + DataFrame, ) -from pandas.core.arrays.sparse import SparseDtype as SparseDtype +from pandas.core.arrays.sparse import SparseDtype -from pandas.tseries.api import infer_freq as infer_freq -from pandas.tseries import offsets as offsets +from pandas.tseries.api import infer_freq +from pandas.tseries import offsets -from pandas.core.computation.api import eval as eval +from pandas.core.computation.api import eval from pandas.core.reshape.api import ( - concat as concat, - lreshape as lreshape, - melt as melt, - wide_to_long as wide_to_long, - merge as merge, - merge_asof as merge_asof, - merge_ordered as merge_ordered, - crosstab as crosstab, - pivot as pivot, - pivot_table as pivot_table, - get_dummies as get_dummies, - cut as cut, - qcut as qcut, + concat, + lreshape, + melt, + wide_to_long, + merge, + merge_asof, + merge_ordered, + crosstab, + pivot, + pivot_table, + get_dummies, + cut, + qcut, ) -import pandas.api -from pandas.util._print_versions import show_versions as show_versions +from pandas import api +from pandas.util._print_versions import show_versions from pandas.io.api import ( # excel - ExcelFile as ExcelFile, - ExcelWriter as ExcelWriter, - read_excel as read_excel, + ExcelFile, + ExcelWriter, + read_excel, # parsers - read_csv as read_csv, - read_fwf as read_fwf, - read_table as read_table, + read_csv, + read_fwf, + read_table, # pickle - read_pickle as read_pickle, - to_pickle as to_pickle, + read_pickle, + to_pickle, # pytables - HDFStore as HDFStore, - read_hdf as read_hdf, + HDFStore, + read_hdf, # sql - read_sql as read_sql, - read_sql_query as read_sql_query, - read_sql_table as read_sql_table, + read_sql, + read_sql_query, + read_sql_table, # misc - read_clipboard as read_clipboard, - read_parquet as read_parquet, - read_orc as read_orc, - read_feather as read_feather, - read_gbq as read_gbq, - read_html as read_html, - read_xml as read_xml, - read_json as read_json, - read_stata as read_stata, - read_sas as read_sas, - read_spss as read_spss, + read_clipboard, + read_parquet, + read_orc, + read_feather, + read_gbq, + read_html, + read_xml, + read_json, + read_stata, + read_sas, + read_spss, ) from pandas.io.json import _json_normalize as json_normalize -from pandas.util._tester import test as test -import pandas.testing -import pandas.arrays +from pandas.util._tester import test +from pandas import testing +from pandas import arrays # use the closest tagged version if possible -from pandas._version import get_versions as get_versions +from pandas._version import get_versions v = get_versions() __version__ = v.get("closest-tag", v["version"]) __git_version__ = v.get("full-revisionid") del get_versions, v - # GH 27101 __deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"] @@ -306,3 +302,118 @@ def __getattr__(name): - Time series-specific functionality: date range generation and frequency conversion, moving window statistics, date shifting and lagging. """ + +# Use __all__ to let type checkers know what is part of the public API. +# Pandas is not (yet) a py.typed library: the public API is determined +# based on the documentation. +__all__ = [ + "get_option", + "set_option", + "reset_option", + "describe_option", + "option_context", + "options", + "Int8Dtype", + "Int16Dtype", + "Int32Dtype", + "Int64Dtype", + "UInt8Dtype", + "UInt16Dtype", + "UInt32Dtype", + "UInt64Dtype", + "Float32Dtype", + "Float64Dtype", + "CategoricalDtype", + "PeriodDtype", + "IntervalDtype", + "DatetimeTZDtype", + "StringDtype", + "BooleanDtype", + "NA", + "isna", + "isnull", + "notna", + "notnull", + "Index", + "CategoricalIndex", + "RangeIndex", + "NumericIndex", + "MultiIndex", + "IntervalIndex", + "TimedeltaIndex", + "DatetimeIndex", + "PeriodIndex", + "IndexSlice", + "NaT", + "Period", + "period_range", + "Timedelta", + "timedelta_range", + "Timestamp", + "date_range", + "bdate_range", + "Interval", + "interval_range", + "DateOffset", + "to_numeric", + "to_datetime", + "to_timedelta", + "Flags", + "Grouper", + "factorize", + "unique", + "value_counts", + "NamedAgg", + "array", + "Categorical", + "set_eng_float_format", + "Series", + "DataFrame", + "SparseDtype", + "infer_freq", + "offsets", + "eval", + "concat", + "lreshape", + "melt", + "wide_to_long", + "merge", + "merge_asof", + "merge_ordered", + "crosstab", + "pivot", + "pivot_table", + "get_dummies", + "cut", + "qcut", + "api", + "show_versions", + "ExcelFile", + "ExcelWriter", + "read_excel", + "read_csv", + "read_fwf", + "read_table", + "read_pickle", + "to_pickle", + "HDFStore", + "read_hdf", + "read_sql", + "read_sql_query", + "read_sql_table", + "read_clipboard", + "read_parquet", + "read_orc", + "read_feather", + "read_gbq", + "read_html", + "read_xml", + "read_json", + "read_stata", + "read_sas", + "read_spss", + "json_normalize", + "test", + "testing", + "arrays", +] From 31bdcd39617d718900f325e40a3284383e402dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Wed, 22 Sep 2021 18:04:26 -0400 Subject: [PATCH 04/10] sort --- pandas/__init__.py | 160 ++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index e4fc9195cdccb..3d83d267f193b 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -307,113 +307,113 @@ def __getattr__(name): # Pandas is not (yet) a py.typed library: the public API is determined # based on the documentation. __all__ = [ - "get_option", - "set_option", - "reset_option", - "describe_option", - "option_context", - "options", - "Int8Dtype", + "BooleanDtype", + "Categorical", + "CategoricalDtype", + "CategoricalIndex", + "DataFrame", + "DateOffset", + "DatetimeIndex", + "DatetimeTZDtype", + "ExcelFile", + "ExcelWriter", + "Flags", + "Float32Dtype", + "Float64Dtype", + "Grouper", + "HDFStore", + "Index", + "IndexSlice", "Int16Dtype", "Int32Dtype", "Int64Dtype", - "UInt8Dtype", - "UInt16Dtype", - "UInt32Dtype", - "UInt64Dtype", - "Float32Dtype", - "Float64Dtype", - "CategoricalDtype", - "PeriodDtype", + "Int8Dtype", + "Interval", "IntervalDtype", - "DatetimeTZDtype", - "StringDtype", - "BooleanDtype", - "NA", - "isna", - "isnull", - "notna", - "notnull", - "Index", - "CategoricalIndex", - "RangeIndex", - "NumericIndex", - "MultiIndex", "IntervalIndex", - "TimedeltaIndex", - "DatetimeIndex", - "PeriodIndex", - "IndexSlice", + "MultiIndex", + "NA", "NaT", + "NamedAgg", + "NumericIndex", "Period", - "period_range", + "PeriodDtype", + "PeriodIndex", + "RangeIndex", + "Series", + "SparseDtype", + "StringDtype", "Timedelta", - "timedelta_range", + "TimedeltaIndex", "Timestamp", - "date_range", + "UInt16Dtype", + "UInt32Dtype", + "UInt64Dtype", + "UInt8Dtype", + "api", + "array", + "arrays", "bdate_range", - "Interval", - "interval_range", - "DateOffset", - "to_numeric", - "to_datetime", - "to_timedelta", - "Flags", - "Grouper", + "concat", + "crosstab", + "cut", + "date_range", + "describe_option", + "eval", "factorize", - "unique", - "value_counts", - "NamedAgg", - "array", - "Categorical", - "set_eng_float_format", - "Series", - "DataFrame", - "SparseDtype", + "get_dummies", + "get_option", "infer_freq", - "offsets", - "eval", - "concat", + "interval_range", + "isna", + "isnull", + "json_normalize", "lreshape", "melt", - "wide_to_long", "merge", "merge_asof", "merge_ordered", - "crosstab", + "notna", + "notnull", + "offsets", + "option_context", + "options", + "period_range", "pivot", "pivot_table", - "get_dummies", - "cut", "qcut", - "api", - "show_versions", - "ExcelFile", - "ExcelWriter", - "read_excel", - "read_csv", - "read_fwf", - "read_table", - "read_pickle", - "to_pickle", - "HDFStore", - "read_hdf", - "read_sql", - "read_sql_query", - "read_sql_table", "read_clipboard", - "read_parquet", - "read_orc", + "read_csv", + "read_excel", "read_feather", + "read_fwf", "read_gbq", + "read_hdf", "read_html", - "read_xml", "read_json", - "read_stata", + "read_orc", + "read_parquet", + "read_pickle", "read_sas", "read_spss", - "json_normalize", + "read_sql", + "read_sql_query", + "read_sql_table", + "read_stata", + "read_table", + "read_xml", + "reset_option", + "set_eng_float_format", + "set_option", + "show_versions", "test", "testing", - "arrays", + "timedelta_range", + "to_datetime", + "to_numeric", + "to_pickle", + "to_timedelta", + "unique", + "value_counts", + "wide_to_long", ] From 44a905e3a4a3dc06a49846d2998f011f640ba745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Wed, 22 Sep 2021 20:35:59 -0400 Subject: [PATCH 05/10] added missing modules and added a test --- pandas/__init__.py | 10 +++++++++- pandas/tests/api/test_api.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 3d83d267f193b..c887142f516b3 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -354,17 +354,21 @@ def __getattr__(name): "array", "arrays", "bdate_range", + "compat", "concat", + "core", "crosstab", "cut", "date_range", "describe_option", + "errors", "eval", "factorize", "get_dummies", "get_option", "infer_freq", "interval_range", + "io", "isna", "isnull", "json_normalize", @@ -378,9 +382,11 @@ def __getattr__(name): "offsets", "option_context", "options", + "pandas", "period_range", "pivot", "pivot_table", + "plotting", "qcut", "read_clipboard", "read_csv", @@ -413,7 +419,9 @@ def __getattr__(name): "to_numeric", "to_pickle", "to_timedelta", + "tseries", "unique", + "util", "value_counts", "wide_to_long", -] +] + __deprecated_num_index_names diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index ef0a9337234ce..191246668835b 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -217,6 +217,26 @@ def test_api(self): ) self.check(namespace=pd, expected=checkthese, ignored=self.ignored) + def test_api_all(self): + expected = set( + self.lib + + self.misc + + self.modules + + self.classes + + self.funcs + + self.funcs_option + + self.funcs_read + + self.funcs_json + + self.funcs_to + ) + actual = set(pd.__all__) + + extraneous = actual - expected + assert not extraneous + + missing = expected - actual + assert not missing + def test_depr(self): deprecated_list = ( self.deprecated_modules From e0d896cf19533201a400960426f96fadeb865dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 23 Sep 2021 08:00:05 -0400 Subject: [PATCH 06/10] remove core, io, ... --- pandas/__init__.py | 8 -------- pandas/tests/api/test_api.py | 13 +++++-------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index c887142f516b3..2d663a8139fb9 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -354,21 +354,17 @@ def __getattr__(name): "array", "arrays", "bdate_range", - "compat", "concat", - "core", "crosstab", "cut", "date_range", "describe_option", - "errors", "eval", "factorize", "get_dummies", "get_option", "infer_freq", "interval_range", - "io", "isna", "isnull", "json_normalize", @@ -382,11 +378,9 @@ def __getattr__(name): "offsets", "option_context", "options", - "pandas", "period_range", "pivot", "pivot_table", - "plotting", "qcut", "read_clipboard", "read_csv", @@ -419,9 +413,7 @@ def __getattr__(name): "to_numeric", "to_pickle", "to_timedelta", - "tseries", "unique", - "util", "value_counts", "wide_to_long", ] + __deprecated_num_index_names diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 191246668835b..2a18351ec2995 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -30,19 +30,15 @@ class TestPDApi(Base): ignored = ["tests", "locale", "conftest"] # top-level sub-packages - lib = [ - "api", - "arrays", + public_lib = ["api", "arrays", "options", "test", "testing"] + private_lib = [ "compat", "core", "errors", "pandas", "plotting", - "test", - "testing", "tseries", "util", - "options", "io", ] @@ -204,7 +200,8 @@ class TestPDApi(Base): def test_api(self): checkthese = ( - self.lib + self.public_lib + + self.private_lib + self.misc + self.modules + self.classes @@ -219,7 +216,7 @@ def test_api(self): def test_api_all(self): expected = set( - self.lib + self.public_lib + self.misc + self.modules + self.classes From dc7ee319f28bb0f670653323a4ca28c0fecda510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 23 Sep 2021 19:15:52 -0400 Subject: [PATCH 07/10] add public modules based on documentation --- pandas/__init__.py | 8 +++++--- pandas/tests/api/test_api.py | 15 ++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 2d663a8139fb9..ce14b0209a1e1 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -131,7 +131,7 @@ qcut, ) -from pandas import api +from pandas import api, arrays, errors, io, plotting, testing, tseries from pandas.util._print_versions import show_versions from pandas.io.api import ( @@ -170,8 +170,6 @@ from pandas.io.json import _json_normalize as json_normalize from pandas.util._tester import test -from pandas import testing -from pandas import arrays # use the closest tagged version if possible from pandas._version import get_versions @@ -359,12 +357,14 @@ def __getattr__(name): "cut", "date_range", "describe_option", + "errors", "eval", "factorize", "get_dummies", "get_option", "infer_freq", "interval_range", + "io", "isna", "isnull", "json_normalize", @@ -381,6 +381,7 @@ def __getattr__(name): "period_range", "pivot", "pivot_table", + "plotting", "qcut", "read_clipboard", "read_csv", @@ -413,6 +414,7 @@ def __getattr__(name): "to_numeric", "to_pickle", "to_timedelta", + "tseries", "unique", "value_counts", "wide_to_long", diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 2a18351ec2995..290f2770fbfc6 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -30,17 +30,18 @@ class TestPDApi(Base): ignored = ["tests", "locale", "conftest"] # top-level sub-packages - public_lib = ["api", "arrays", "options", "test", "testing"] - private_lib = [ - "compat", - "core", + public_lib = [ + "api", + "arrays", + "options", + "test", + "testing", "errors", - "pandas", "plotting", - "tseries", - "util", "io", + "tseries", ] + private_lib = ["compat", "core", "pandas", "util"] # these are already deprecated; awaiting removal deprecated_modules: list[str] = ["np", "datetime"] From f127eb6da7bf5c2190ce460fa475245a73bdf783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 23 Sep 2021 22:22:59 -0400 Subject: [PATCH 08/10] io and tseries: recursively add documented to be public modules to __all__ (everything else is technically private) --- pandas/io/__init__.py | 12 ++++++++++++ pandas/io/formats/__init__.py | 8 ++++++++ pandas/tseries/__init__.py | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/pandas/io/__init__.py b/pandas/io/__init__.py index e69de29bb2d1d..bd3ddc09393d8 100644 --- a/pandas/io/__init__.py +++ b/pandas/io/__init__.py @@ -0,0 +1,12 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + # import modules that have public classes/functions + from pandas.io import ( + formats, + json, + stata, + ) + + # and mark only those modules as public + __all__ = ["formats", "json", "stata"] diff --git a/pandas/io/formats/__init__.py b/pandas/io/formats/__init__.py index e69de29bb2d1d..8a3486a4d71fe 100644 --- a/pandas/io/formats/__init__.py +++ b/pandas/io/formats/__init__.py @@ -0,0 +1,8 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + # import modules that have public classes/functions + from pandas.io.formats import style + + # and mark only those modules as public + __all__ = ["style"] diff --git a/pandas/tseries/__init__.py b/pandas/tseries/__init__.py index e69de29bb2d1d..dd4ce02b19453 100644 --- a/pandas/tseries/__init__.py +++ b/pandas/tseries/__init__.py @@ -0,0 +1,11 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + # import modules that have public classes/functions: + from pandas.tseries import ( + frequencies, + offsets, + ) + + # and mark only those modules as public + __all__ = ["frequencies", "offsets"] From e5c766ba0f8571956d0f02d127a04101a219252c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Tue, 28 Sep 2021 15:39:45 -0400 Subject: [PATCH 09/10] remove deprecated functions from __all__ --- pandas/__init__.py | 182 +++++++++++++++++------------------ pandas/tests/api/test_api.py | 2 +- 2 files changed, 91 insertions(+), 93 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index ce14b0209a1e1..2a9ce4cce5f20 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -22,7 +22,11 @@ from pandas.compat import is_numpy_dev as _is_numpy_dev try: - from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib + from pandas._libs import ( + hashtable as _hashtable, + lib as _lib, + tslib as _tslib, + ) except ImportError as e: # pragma: no cover module = e.name raise ImportError( @@ -32,147 +36,137 @@ ) from e from pandas._config import ( - get_option, - set_option, - reset_option, describe_option, + get_option, option_context, options, + reset_option, + set_option, ) -# let init-time option registration happen -import pandas.core.config_init +from pandas.util._print_versions import show_versions +from pandas.util._tester import test + +from pandas import ( + api, + arrays, + errors, + io, + plotting, + testing, + tseries, +) -from pandas.core.api import ( - # dtype +# use the closest tagged version if possible +from pandas._version import get_versions +from pandas.core.api import ( # dtype; missing; indexes; tseries; conversion; misc + NA, + BooleanDtype, + Categorical, + CategoricalDtype, + CategoricalIndex, + DataFrame, + DateOffset, + DatetimeIndex, + DatetimeTZDtype, + Flags, + Float32Dtype, + Float64Dtype, + Grouper, + Index, + IndexSlice, Int8Dtype, Int16Dtype, Int32Dtype, Int64Dtype, + Interval, + IntervalDtype, + IntervalIndex, + MultiIndex, + NamedAgg, + NaT, + NumericIndex, + Period, + PeriodDtype, + PeriodIndex, + RangeIndex, + Series, + StringDtype, + Timedelta, + TimedeltaIndex, + Timestamp, UInt8Dtype, UInt16Dtype, UInt32Dtype, UInt64Dtype, - Float32Dtype, - Float64Dtype, - CategoricalDtype, - PeriodDtype, - IntervalDtype, - DatetimeTZDtype, - StringDtype, - BooleanDtype, - # missing - NA, + array, + bdate_range, + date_range, + factorize, + interval_range, isna, isnull, notna, notnull, - # indexes - Index, - CategoricalIndex, - RangeIndex, - NumericIndex, - MultiIndex, - IntervalIndex, - TimedeltaIndex, - DatetimeIndex, - PeriodIndex, - IndexSlice, - # tseries - NaT, - Period, period_range, - Timedelta, + set_eng_float_format, timedelta_range, - Timestamp, - date_range, - bdate_range, - Interval, - interval_range, - DateOffset, - # conversion - to_numeric, to_datetime, + to_numeric, to_timedelta, - # misc - Flags, - Grouper, - factorize, unique, value_counts, - NamedAgg, - array, - Categorical, - set_eng_float_format, - Series, - DataFrame, ) - from pandas.core.arrays.sparse import SparseDtype - -from pandas.tseries.api import infer_freq -from pandas.tseries import offsets - from pandas.core.computation.api import eval +# let init-time option registration happen +import pandas.core.config_init from pandas.core.reshape.api import ( concat, + crosstab, + cut, + get_dummies, lreshape, melt, - wide_to_long, merge, merge_asof, merge_ordered, - crosstab, pivot, pivot_table, - get_dummies, - cut, qcut, + wide_to_long, ) -from pandas import api, arrays, errors, io, plotting, testing, tseries -from pandas.util._print_versions import show_versions - -from pandas.io.api import ( - # excel +from pandas.io.api import ( # excel; parsers; pickle; pytables; sql; misc ExcelFile, ExcelWriter, - read_excel, - # parsers - read_csv, - read_fwf, - read_table, - # pickle - read_pickle, - to_pickle, - # pytables HDFStore, - read_hdf, - # sql - read_sql, - read_sql_query, - read_sql_table, - # misc read_clipboard, - read_parquet, - read_orc, + read_csv, + read_excel, read_feather, + read_fwf, read_gbq, + read_hdf, read_html, - read_xml, read_json, - read_stata, + read_orc, + read_parquet, + read_pickle, read_sas, read_spss, + read_sql, + read_sql_query, + read_sql_table, + read_stata, + read_table, + read_xml, + to_pickle, ) - from pandas.io.json import _json_normalize as json_normalize - -from pandas.util._tester import test - -# use the closest tagged version if possible -from pandas._version import get_versions +from pandas.tseries import offsets +from pandas.tseries.api import infer_freq v = get_versions() __version__ = v.get("closest-tag", v["version"]) @@ -201,7 +195,11 @@ def __getattr__(name): FutureWarning, stacklevel=2, ) - from pandas.core.api import Float64Index, Int64Index, UInt64Index + from pandas.core.api import ( + Float64Index, + Int64Index, + UInt64Index, + ) return { "Float64Index": Float64Index, @@ -418,4 +416,4 @@ def __getattr__(name): "unique", "value_counts", "wide_to_long", -] + __deprecated_num_index_names +] diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 290f2770fbfc6..ec20bc49c8a4b 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -226,7 +226,7 @@ def test_api_all(self): + self.funcs_read + self.funcs_json + self.funcs_to - ) + ) - set(self.deprecated_classes) actual = set(pd.__all__) extraneous = actual - expected From c953389832d76ef77edbb89b1eac4a300494814e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Tue, 28 Sep 2021 15:42:20 -0400 Subject: [PATCH 10/10] dont reformat init --- pandas/__init__.py | 180 +++++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 2a9ce4cce5f20..9505d0481ee19 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -22,11 +22,7 @@ from pandas.compat import is_numpy_dev as _is_numpy_dev try: - from pandas._libs import ( - hashtable as _hashtable, - lib as _lib, - tslib as _tslib, - ) + from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib except ImportError as e: # pragma: no cover module = e.name raise ImportError( @@ -36,137 +32,147 @@ ) from e from pandas._config import ( - describe_option, get_option, + set_option, + reset_option, + describe_option, option_context, options, - reset_option, - set_option, ) -from pandas.util._print_versions import show_versions -from pandas.util._tester import test - -from pandas import ( - api, - arrays, - errors, - io, - plotting, - testing, - tseries, -) +# let init-time option registration happen +import pandas.core.config_init -# use the closest tagged version if possible -from pandas._version import get_versions -from pandas.core.api import ( # dtype; missing; indexes; tseries; conversion; misc - NA, - BooleanDtype, - Categorical, - CategoricalDtype, - CategoricalIndex, - DataFrame, - DateOffset, - DatetimeIndex, - DatetimeTZDtype, - Flags, - Float32Dtype, - Float64Dtype, - Grouper, - Index, - IndexSlice, +from pandas.core.api import ( + # dtype Int8Dtype, Int16Dtype, Int32Dtype, Int64Dtype, - Interval, - IntervalDtype, - IntervalIndex, - MultiIndex, - NamedAgg, - NaT, - NumericIndex, - Period, - PeriodDtype, - PeriodIndex, - RangeIndex, - Series, - StringDtype, - Timedelta, - TimedeltaIndex, - Timestamp, UInt8Dtype, UInt16Dtype, UInt32Dtype, UInt64Dtype, - array, - bdate_range, - date_range, - factorize, - interval_range, + Float32Dtype, + Float64Dtype, + CategoricalDtype, + PeriodDtype, + IntervalDtype, + DatetimeTZDtype, + StringDtype, + BooleanDtype, + # missing + NA, isna, isnull, notna, notnull, + # indexes + Index, + CategoricalIndex, + RangeIndex, + NumericIndex, + MultiIndex, + IntervalIndex, + TimedeltaIndex, + DatetimeIndex, + PeriodIndex, + IndexSlice, + # tseries + NaT, + Period, period_range, - set_eng_float_format, + Timedelta, timedelta_range, - to_datetime, + Timestamp, + date_range, + bdate_range, + Interval, + interval_range, + DateOffset, + # conversion to_numeric, + to_datetime, to_timedelta, + # misc + Flags, + Grouper, + factorize, unique, value_counts, + NamedAgg, + array, + Categorical, + set_eng_float_format, + Series, + DataFrame, ) + from pandas.core.arrays.sparse import SparseDtype + +from pandas.tseries.api import infer_freq +from pandas.tseries import offsets + from pandas.core.computation.api import eval -# let init-time option registration happen -import pandas.core.config_init from pandas.core.reshape.api import ( concat, - crosstab, - cut, - get_dummies, lreshape, melt, + wide_to_long, merge, merge_asof, merge_ordered, + crosstab, pivot, pivot_table, + get_dummies, + cut, qcut, - wide_to_long, ) -from pandas.io.api import ( # excel; parsers; pickle; pytables; sql; misc +from pandas import api, arrays, errors, io, plotting, testing, tseries +from pandas.util._print_versions import show_versions + +from pandas.io.api import ( + # excel ExcelFile, ExcelWriter, + read_excel, + # parsers + read_csv, + read_fwf, + read_table, + # pickle + read_pickle, + to_pickle, + # pytables HDFStore, + read_hdf, + # sql + read_sql, + read_sql_query, + read_sql_table, + # misc read_clipboard, - read_csv, - read_excel, + read_parquet, + read_orc, read_feather, - read_fwf, read_gbq, - read_hdf, read_html, + read_xml, read_json, - read_orc, - read_parquet, - read_pickle, + read_stata, read_sas, read_spss, - read_sql, - read_sql_query, - read_sql_table, - read_stata, - read_table, - read_xml, - to_pickle, ) + from pandas.io.json import _json_normalize as json_normalize -from pandas.tseries import offsets -from pandas.tseries.api import infer_freq + +from pandas.util._tester import test + +# use the closest tagged version if possible +from pandas._version import get_versions v = get_versions() __version__ = v.get("closest-tag", v["version"]) @@ -195,11 +201,7 @@ def __getattr__(name): FutureWarning, stacklevel=2, ) - from pandas.core.api import ( - Float64Index, - Int64Index, - UInt64Index, - ) + from pandas.core.api import Float64Index, Int64Index, UInt64Index return { "Float64Index": Float64Index,