diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 8a628dbce3ca7..5d830afc9f74a 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -225,7 +225,7 @@ Removal of prior version deprecations/changes - Removed ``pandas.util.testing`` in favor of ``pandas.testing`` (:issue:`30745`) - Removed :meth:`Series.str.__iter__` (:issue:`28277`) - Removed ``pandas.SparseArray`` in favor of :class:`arrays.SparseArray` (:issue:`30642`) -- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame`` (:issue:`30642`) +- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame``, including pickle support. (:issue:`30642`) - Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`) - Removed setting Categorical._codes directly (:issue:`41429`) - Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index c233e3d8a4892..051aa5c337782 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -7,11 +7,7 @@ import copy import io import pickle as pkl -from typing import ( - TYPE_CHECKING, - Generator, -) -import warnings +from typing import Generator import numpy as np @@ -26,12 +22,6 @@ ) from pandas.core.internals import BlockManager -if TYPE_CHECKING: - from pandas import ( - DataFrame, - Series, - ) - def load_reduce(self): stack = self.stack @@ -68,49 +58,6 @@ def load_reduce(self): raise -_sparse_msg = """\ - -Loading a saved '{cls}' as a {new} with sparse values. -'{cls}' is now removed. You should re-save this dataset in its new format. -""" - - -class _LoadSparseSeries: - # To load a SparseSeries as a Series[Sparse] - - # https://github.com/python/mypy/issues/1020 - # error: Incompatible return type for "__new__" (returns "Series", but must return - # a subtype of "_LoadSparseSeries") - def __new__(cls) -> Series: # type: ignore[misc] - from pandas import Series - - warnings.warn( - _sparse_msg.format(cls="SparseSeries", new="Series"), - FutureWarning, - stacklevel=6, - ) - - return Series(dtype=object) - - -class _LoadSparseFrame: - # To load a SparseDataFrame as a DataFrame[Sparse] - - # https://github.com/python/mypy/issues/1020 - # error: Incompatible return type for "__new__" (returns "DataFrame", but must - # return a subtype of "_LoadSparseFrame") - def __new__(cls) -> DataFrame: # type: ignore[misc] - from pandas import DataFrame - - warnings.warn( - _sparse_msg.format(cls="SparseDataFrame", new="DataFrame"), - FutureWarning, - stacklevel=6, - ) - - return DataFrame() - - # If classes are moved, provide compat here. _class_locations_map = { ("pandas.core.sparse.array", "SparseArray"): ("pandas.core.arrays", "SparseArray"), @@ -144,14 +91,6 @@ def __new__(cls) -> DataFrame: # type: ignore[misc] "pandas.core.arrays.sparse", "SparseArray", ), - ("pandas.sparse.series", "SparseSeries"): ( - "pandas.compat.pickle_compat", - "_LoadSparseSeries", - ), - ("pandas.sparse.frame", "SparseDataFrame"): ( - "pandas.core.sparse.frame", - "_LoadSparseFrame", - ), ("pandas.indexes.base", "_new_Index"): ("pandas.core.indexes.base", "_new_Index"), ("pandas.indexes.base", "Index"): ("pandas.core.indexes.base", "Index"), ("pandas.indexes.numeric", "Int64Index"): ( @@ -183,14 +122,6 @@ def __new__(cls) -> DataFrame: # type: ignore[misc] "pandas.core.indexes.numeric", "Float64Index", ), - ("pandas.core.sparse.series", "SparseSeries"): ( - "pandas.compat.pickle_compat", - "_LoadSparseSeries", - ), - ("pandas.core.sparse.frame", "SparseDataFrame"): ( - "pandas.compat.pickle_compat", - "_LoadSparseFrame", - ), } diff --git a/pandas/tests/io/data/legacy_pickle/0.20.3/0.20.3_x86_64_darwin_3.5.2.pickle b/pandas/tests/io/data/legacy_pickle/0.20.3/0.20.3_x86_64_darwin_3.5.2.pickle deleted file mode 100644 index 9777319465de6..0000000000000 Binary files a/pandas/tests/io/data/legacy_pickle/0.20.3/0.20.3_x86_64_darwin_3.5.2.pickle and /dev/null differ diff --git a/pandas/tests/io/data/legacy_pickle/0.20.3/0.20.3_x86_64_darwin_3.5.6.pickle b/pandas/tests/io/data/legacy_pickle/0.20.3/0.20.3_x86_64_darwin_3.5.6.pickle deleted file mode 100644 index 88bb6989f5b08..0000000000000 Binary files a/pandas/tests/io/data/legacy_pickle/0.20.3/0.20.3_x86_64_darwin_3.5.6.pickle and /dev/null differ diff --git a/pandas/tests/io/data/pickle/sparseframe-0.20.3.pickle.gz b/pandas/tests/io/data/pickle/sparseframe-0.20.3.pickle.gz deleted file mode 100644 index f4ff0dbaa1ff9..0000000000000 Binary files a/pandas/tests/io/data/pickle/sparseframe-0.20.3.pickle.gz and /dev/null differ diff --git a/pandas/tests/io/data/pickle/sparseseries-0.20.3.pickle.gz b/pandas/tests/io/data/pickle/sparseseries-0.20.3.pickle.gz deleted file mode 100644 index b299e7d85808e..0000000000000 Binary files a/pandas/tests/io/data/pickle/sparseseries-0.20.3.pickle.gz and /dev/null differ diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index d78cb9e46cd1a..5115a33694207 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -254,28 +254,6 @@ def test_pickle_path_localpath(): tm.assert_frame_equal(df, result) -@pytest.mark.parametrize("typ", ["sparseseries", "sparseframe"]) -def test_legacy_sparse_warning(datapath, typ): - """ - - Generated with - - >>> df = pd.DataFrame({"A": [1, 2, 3, 4], "B": [0, 0, 1, 1]}).to_sparse() - >>> df.to_pickle("pandas/tests/io/data/pickle/sparseframe-0.20.3.pickle.gz", - ... compression="gzip") - - >>> s = df['B'] - >>> s.to_pickle("pandas/tests/io/data/pickle/sparseseries-0.20.3.pickle.gz", - ... compression="gzip") - """ - with tm.assert_produces_warning(FutureWarning): - simplefilter("ignore", DeprecationWarning) # from boto - pd.read_pickle( - datapath("io", "data", "pickle", f"{typ}-0.20.3.pickle.gz"), - compression="gzip", - ) - - # --------------------- # test pickle compression # ---------------------