diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index bdb4e813023b6..72e2413ce87d9 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -1,3 +1,4 @@ +import sys from typing import List import pandas as pd @@ -288,14 +289,20 @@ def test_testing(self): self.check(testing, self.funcs) def test_util_testing_deprecated(self): - s = pd.Series([], dtype="object") - with tm.assert_produces_warning(FutureWarning) as m: - import pandas.util.testing as tm2 + # avoid cache state affecting the test + sys.modules.pop("pandas.util.testing", None) - tm2.assert_series_equal(s, s) + with tm.assert_produces_warning(FutureWarning) as m: + import pandas.util.testing # noqa: F401 - assert "pandas.testing.assert_series_equal" in str(m[0].message) + assert "pandas.util.testing is deprecated" in str(m[0].message) + assert "pandas.testing instead" in str(m[0].message) + def test_util_testing_deprecated_direct(self): + # avoid cache state affecting the test + sys.modules.pop("pandas.util.testing", None) with tm.assert_produces_warning(FutureWarning) as m: - tm2.DataFrame - assert "removed" in str(m[0].message) + from pandas.util.testing import assert_series_equal # noqa: F401 + + assert "pandas.util.testing is deprecated" in str(m[0].message) + assert "pandas.testing instead" in str(m[0].message) diff --git a/pandas/util/__init__.py b/pandas/util/__init__.py index 231a23e247650..d906c0371d207 100644 --- a/pandas/util/__init__.py +++ b/pandas/util/__init__.py @@ -1,4 +1,3 @@ from pandas.util._decorators import Appender, Substitution, cache_readonly # noqa from pandas.core.util.hashing import hash_array, hash_pandas_object # noqa -from pandas.util.testing import testing # noqa: F401 diff --git a/pandas/util/testing.py b/pandas/util/testing.py new file mode 100644 index 0000000000000..af9fe4846b27d --- /dev/null +++ b/pandas/util/testing.py @@ -0,0 +1,12 @@ +import warnings + +from pandas._testing import * # noqa + +warnings.warn( + ( + "pandas.util.testing is deprecated. Use the functions in the " + "public API at pandas.testing instead." + ), + FutureWarning, + stacklevel=2, +) diff --git a/pandas/util/testing/__init__.py b/pandas/util/testing/__init__.py deleted file mode 100644 index 02cbd19a9a888..0000000000000 --- a/pandas/util/testing/__init__.py +++ /dev/null @@ -1,144 +0,0 @@ -from pandas.util._depr_module import _DeprecatedModule - -_removals = [ - "Categorical", - "CategoricalIndex", - "Counter", - "DataFrame", - "DatetimeArray", - "DatetimeIndex", - "ExtensionArray", - "FrameOrSeries", - "Index", - "IntervalArray", - "IntervalIndex", - "K", - "List", - "MultiIndex", - "N", - "Optional", - "PeriodArray", - "RANDS_CHARS", - "RANDU_CHARS", - "RNGContext", - "RangeIndex", - "Series", - "SubclassedCategorical", - "SubclassedDataFrame", - "SubclassedSeries", - "TimedeltaArray", - "Union", - "all_index_generator", - "all_timeseries_index_generator", - "array_equivalent", - "assert_attr_equal", - "assert_class_equal", - "assert_contains_all", - "assert_copy", - "assert_dict_equal", - "assert_is_sorted", - "assert_is_valid_plot_return_object", - "assert_produces_warning", - "bdate_range", - "box_expected", - "bz2", - "can_connect", - "can_set_locale", - "cast", - "close", - "contextmanager", - "convert_rows_list_to_csv_str", - "datetime", - "decompress_file", - "ensure_clean", - "ensure_clean_dir", - "ensure_safe_environment_variables", - "equalContents", - "getCols", - "getMixedTypeDict", - "getPeriodData", - "getSeriesData", - "getTimeSeriesData", - "get_locales", - "gzip", - "index_subclass_makers_generator", - "is_bool", - "is_categorical_dtype", - "is_datetime64_dtype", - "is_datetime64tz_dtype", - "is_extension_array_dtype", - "is_interval_dtype", - "is_list_like", - "is_number", - "is_period_dtype", - "is_sequence", - "is_timedelta64_dtype", - "isiterable", - "lzma", - "makeBoolIndex", - "makeCategoricalIndex", - "makeCustomDataframe", - "makeCustomIndex", - "makeDataFrame", - "makeDateIndex", - "makeFloatIndex", - "makeFloatSeries", - "makeIntIndex", - "makeIntervalIndex", - "makeMissingCustomDataframe", - "makeMissingDataframe", - "makeMixedDataFrame", - "makeMultiIndex", - "makeObjectSeries", - "makePeriodFrame", - "makePeriodIndex", - "makePeriodSeries", - "makeRangeIndex", - "makeStringIndex", - "makeStringSeries", - "makeTimeDataFrame", - "makeTimeSeries", - "makeTimedeltaIndex", - "makeUIntIndex", - "makeUnicodeIndex", - "needs_i8_conversion", - "network", - "np", - "optional_args", - "os", - "pd", - "period_array", - "pprint_thing", - "raise_assert_detail", - "rand", - "randbool", - "randn", - "rands", - "rands_array", - "randu", - "randu_array", - "reset_display_options", - "reset_testing_mode", - "rmtree", - "round_trip_localpath", - "round_trip_pathlib", - "round_trip_pickle", - "set_locale", - "set_testing_mode", - "set_timezone", - "string", - "take_1d", - "tempfile", - "test_parallel", - "to_array", - "urlopen", - "use_numexpr", - "warnings", - "with_connectivity_check", - "with_csv_dialect", - "wraps", - "write_to_compressed", - "zipfile", -] - -testing = _DeprecatedModule("pandas._testing", "pandas.testing", _removals)