diff --git a/doc/source/whatsnew/v0.19.0.rst b/doc/source/whatsnew/v0.19.0.rst index f2fdd23af1297..0c992cf3cc462 100644 --- a/doc/source/whatsnew/v0.19.0.rst +++ b/doc/source/whatsnew/v0.19.0.rst @@ -1245,10 +1245,9 @@ Previously, sparse data were ``float64`` dtype by default, even if all inputs we As of v0.19.0, sparse data keeps the input dtype, and uses more appropriate ``fill_value`` defaults (``0`` for ``int64`` dtype, ``False`` for ``bool`` dtype). .. ipython:: python - :okwarning: - pd.SparseArray([1, 2, 0, 0], dtype=np.int64) - pd.SparseArray([True, False, False, False]) + pd.arrays.SparseArray([1, 2, 0, 0], dtype=np.int64) + pd.arrays.SparseArray([True, False, False, False]) See the :ref:`docs ` for more details. diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index e4dd6fa091d80..0c02287321c49 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -359,9 +359,8 @@ When passed DataFrames whose values are sparse, :func:`concat` will now return a :class:`Series` or :class:`DataFrame` with sparse values, rather than a :class:`SparseDataFrame` (:issue:`25702`). .. ipython:: python - :okwarning: - df = pd.DataFrame({"A": pd.SparseArray([0, 1])}) + df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1])}) *Previous behavior*: @@ -918,9 +917,8 @@ by a ``Series`` or ``DataFrame`` with sparse values. **New way** .. ipython:: python - :okwarning: - df = pd.DataFrame({"A": pd.SparseArray([0, 0, 1, 2])}) + df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 0, 1, 2])}) df.dtypes The memory usage of the two approaches is identical. See :ref:`sparse.migration` for more (:issue:`19239`). diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 317ff168f3177..e281e250d608e 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -190,6 +190,10 @@ Removal of prior version deprecations/changes - Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) - Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`) - Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`) +- Removed the ``pandas.datetime`` submodule (:issue:`30489`) +- Removed the ``pandas.np`` submodule (:issue:`30296`) +- Removed ``pandas.SparseArray`` in favor of :class:`arrays.SparseArray` (:issue:`30642`) +- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame`` (:issue:`30642`) - Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`) - Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`) - diff --git a/pandas/__init__.py b/pandas/__init__.py index 5016bde000c3b..cae768dae722e 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -212,54 +212,6 @@ def __getattr__(name): "Int64Index": Int64Index, "UInt64Index": UInt64Index, }[name] - elif name == "datetime": - warnings.warn( - "The pandas.datetime class is deprecated " - "and will be removed from pandas in a future version. " - "Import from datetime module instead.", - FutureWarning, - stacklevel=2, - ) - - from datetime import datetime as dt - - return dt - - elif name == "np": - - warnings.warn( - "The pandas.np module is deprecated " - "and will be removed from pandas in a future version. " - "Import numpy directly instead.", - FutureWarning, - stacklevel=2, - ) - import numpy as np - - return np - - elif name in {"SparseSeries", "SparseDataFrame"}: - warnings.warn( - f"The {name} class is removed from pandas. Accessing it from " - "the top-level namespace will also be removed in the next version.", - FutureWarning, - stacklevel=2, - ) - - return type(name, (), {}) - - elif name == "SparseArray": - - warnings.warn( - "The pandas.SparseArray class is deprecated " - "and will be removed from pandas in a future version. " - "Use pandas.arrays.SparseArray instead.", - FutureWarning, - stacklevel=2, - ) - from pandas.core.arrays.sparse import SparseArray as _SparseArray - - return _SparseArray raise AttributeError(f"module 'pandas' has no attribute '{name}'") diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index e106fea90b0e2..5149dc0973b79 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -66,9 +66,9 @@ def from_coo(cls, A, dense_index: bool = False) -> Series: ---------- A : scipy.sparse.coo_matrix dense_index : bool, default False - If False (default), the SparseSeries index consists of only the + If False (default), the index consists of only the coords of the non-null entries of the original coo_matrix. - If True, the SparseSeries index consists of the full sorted + If True, the index consists of the full sorted (row, col) coordinates of the coo_matrix. Returns diff --git a/pandas/core/arrays/sparse/scipy_sparse.py b/pandas/core/arrays/sparse/scipy_sparse.py index 88e1778d4c854..3ef5ba5835d79 100644 --- a/pandas/core/arrays/sparse/scipy_sparse.py +++ b/pandas/core/arrays/sparse/scipy_sparse.py @@ -177,7 +177,7 @@ def coo_to_sparse_series( A: scipy.sparse.coo_matrix, dense_index: bool = False ) -> Series: """ - Convert a scipy.sparse.coo_matrix to a SparseSeries. + Convert a scipy.sparse.coo_matrix to a Series with type sparse. Parameters ---------- diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index c2db9698d0537..be704d8eb3e7e 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -45,9 +45,6 @@ class TestPDApi(Base): ] private_lib = ["compat", "core", "pandas", "util"] - # these are already deprecated; awaiting removal - deprecated_modules: list[str] = ["np", "datetime"] - # misc misc = ["IndexSlice", "NaT", "NA"] @@ -101,9 +98,6 @@ class TestPDApi(Base): # these are already deprecated; awaiting removal deprecated_classes: list[str] = ["Float64Index", "Int64Index", "UInt64Index"] - # these should be deprecated in the future - deprecated_classes_in_future: list[str] = ["SparseArray"] - # external modules exposed in pandas namespace modules: list[str] = [] @@ -237,9 +231,7 @@ def test_api_all(self): def test_depr(self): deprecated_list = ( - self.deprecated_modules - + self.deprecated_classes - + self.deprecated_classes_in_future + self.deprecated_classes + self.deprecated_funcs + self.deprecated_funcs_in_future ) @@ -248,35 +240,6 @@ def test_depr(self): _ = getattr(pd, depr) -def test_datetime(): - from datetime import datetime - import warnings - - with warnings.catch_warnings(): - warnings.simplefilter("ignore", FutureWarning) - assert datetime(2015, 1, 2, 0, 0) == datetime(2015, 1, 2, 0, 0) - - assert isinstance(datetime(2015, 1, 2, 0, 0), datetime) - - -def test_sparsearray(): - import warnings - - with warnings.catch_warnings(): - warnings.simplefilter("ignore", FutureWarning) - assert isinstance(pd.array([1, 2, 3], dtype="Sparse"), pd.SparseArray) - - -def test_np(): - import warnings - - import numpy as np - - with warnings.catch_warnings(): - warnings.simplefilter("ignore", FutureWarning) - assert (pd.np.arange(0, 10) == np.arange(0, 10)).all() - - class TestApi(Base): allowed = ["types", "extensions", "indexers", "interchange"] diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index 1a32c995f4afa..a2b8c071b9d3c 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -13,7 +13,7 @@ @pytest.fixture(params=["integer", "block"]) def kind(request): - """kind kwarg to pass to SparseArray/SparseSeries""" + """kind kwarg to pass to SparseArray""" return request.param