Skip to content

Commit 0c527c7

Browse files
mroeschkenoatamir
authored andcommitted
DEPR: Remove top level numpy/datetime/Sparse object imports (pandas-dev#49218)
* Remove pd.np/datetime * Remove SparseArray * Remove SparseSeries & SparseDataFrame * Whatsnew formatting * Address whatsnew notes
1 parent bd491ef commit 0c527c7

File tree

8 files changed

+13
-97
lines changed

8 files changed

+13
-97
lines changed

doc/source/whatsnew/v0.19.0.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -1245,10 +1245,9 @@ Previously, sparse data were ``float64`` dtype by default, even if all inputs we
12451245
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).
12461246

12471247
.. ipython:: python
1248-
:okwarning:
12491248
1250-
pd.SparseArray([1, 2, 0, 0], dtype=np.int64)
1251-
pd.SparseArray([True, False, False, False])
1249+
pd.arrays.SparseArray([1, 2, 0, 0], dtype=np.int64)
1250+
pd.arrays.SparseArray([True, False, False, False])
12521251
12531252
See the :ref:`docs <sparse.dtype>` for more details.
12541253

doc/source/whatsnew/v0.25.0.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,8 @@ When passed DataFrames whose values are sparse, :func:`concat` will now return a
359359
:class:`Series` or :class:`DataFrame` with sparse values, rather than a :class:`SparseDataFrame` (:issue:`25702`).
360360

361361
.. ipython:: python
362-
:okwarning:
363362
364-
df = pd.DataFrame({"A": pd.SparseArray([0, 1])})
363+
df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1])})
365364
366365
*Previous behavior*:
367366

@@ -918,9 +917,8 @@ by a ``Series`` or ``DataFrame`` with sparse values.
918917
**New way**
919918
920919
.. ipython:: python
921-
:okwarning:
922920
923-
df = pd.DataFrame({"A": pd.SparseArray([0, 0, 1, 2])})
921+
df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 0, 1, 2])})
924922
df.dtypes
925923
926924
The memory usage of the two approaches is identical. See :ref:`sparse.migration` for more (:issue:`19239`).

doc/source/whatsnew/v2.0.0.rst

+4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ Removal of prior version deprecations/changes
190190
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
191191
- Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`)
192192
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
193+
- Removed the ``pandas.datetime`` submodule (:issue:`30489`)
194+
- Removed the ``pandas.np`` submodule (:issue:`30296`)
195+
- Removed ``pandas.SparseArray`` in favor of :class:`arrays.SparseArray` (:issue:`30642`)
196+
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame`` (:issue:`30642`)
193197
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
194198
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
195199
-

pandas/__init__.py

-48
Original file line numberDiff line numberDiff line change
@@ -212,54 +212,6 @@ def __getattr__(name):
212212
"Int64Index": Int64Index,
213213
"UInt64Index": UInt64Index,
214214
}[name]
215-
elif name == "datetime":
216-
warnings.warn(
217-
"The pandas.datetime class is deprecated "
218-
"and will be removed from pandas in a future version. "
219-
"Import from datetime module instead.",
220-
FutureWarning,
221-
stacklevel=2,
222-
)
223-
224-
from datetime import datetime as dt
225-
226-
return dt
227-
228-
elif name == "np":
229-
230-
warnings.warn(
231-
"The pandas.np module is deprecated "
232-
"and will be removed from pandas in a future version. "
233-
"Import numpy directly instead.",
234-
FutureWarning,
235-
stacklevel=2,
236-
)
237-
import numpy as np
238-
239-
return np
240-
241-
elif name in {"SparseSeries", "SparseDataFrame"}:
242-
warnings.warn(
243-
f"The {name} class is removed from pandas. Accessing it from "
244-
"the top-level namespace will also be removed in the next version.",
245-
FutureWarning,
246-
stacklevel=2,
247-
)
248-
249-
return type(name, (), {})
250-
251-
elif name == "SparseArray":
252-
253-
warnings.warn(
254-
"The pandas.SparseArray class is deprecated "
255-
"and will be removed from pandas in a future version. "
256-
"Use pandas.arrays.SparseArray instead.",
257-
FutureWarning,
258-
stacklevel=2,
259-
)
260-
from pandas.core.arrays.sparse import SparseArray as _SparseArray
261-
262-
return _SparseArray
263215

264216
raise AttributeError(f"module 'pandas' has no attribute '{name}'")
265217

pandas/core/arrays/sparse/accessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def from_coo(cls, A, dense_index: bool = False) -> Series:
6666
----------
6767
A : scipy.sparse.coo_matrix
6868
dense_index : bool, default False
69-
If False (default), the SparseSeries index consists of only the
69+
If False (default), the index consists of only the
7070
coords of the non-null entries of the original coo_matrix.
71-
If True, the SparseSeries index consists of the full sorted
71+
If True, the index consists of the full sorted
7272
(row, col) coordinates of the coo_matrix.
7373
7474
Returns

pandas/core/arrays/sparse/scipy_sparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def coo_to_sparse_series(
177177
A: scipy.sparse.coo_matrix, dense_index: bool = False
178178
) -> Series:
179179
"""
180-
Convert a scipy.sparse.coo_matrix to a SparseSeries.
180+
Convert a scipy.sparse.coo_matrix to a Series with type sparse.
181181
182182
Parameters
183183
----------

pandas/tests/api/test_api.py

+1-38
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ class TestPDApi(Base):
4545
]
4646
private_lib = ["compat", "core", "pandas", "util"]
4747

48-
# these are already deprecated; awaiting removal
49-
deprecated_modules: list[str] = ["np", "datetime"]
50-
5148
# misc
5249
misc = ["IndexSlice", "NaT", "NA"]
5350

@@ -101,9 +98,6 @@ class TestPDApi(Base):
10198
# these are already deprecated; awaiting removal
10299
deprecated_classes: list[str] = ["Float64Index", "Int64Index", "UInt64Index"]
103100

104-
# these should be deprecated in the future
105-
deprecated_classes_in_future: list[str] = ["SparseArray"]
106-
107101
# external modules exposed in pandas namespace
108102
modules: list[str] = []
109103

@@ -237,9 +231,7 @@ def test_api_all(self):
237231

238232
def test_depr(self):
239233
deprecated_list = (
240-
self.deprecated_modules
241-
+ self.deprecated_classes
242-
+ self.deprecated_classes_in_future
234+
self.deprecated_classes
243235
+ self.deprecated_funcs
244236
+ self.deprecated_funcs_in_future
245237
)
@@ -248,35 +240,6 @@ def test_depr(self):
248240
_ = getattr(pd, depr)
249241

250242

251-
def test_datetime():
252-
from datetime import datetime
253-
import warnings
254-
255-
with warnings.catch_warnings():
256-
warnings.simplefilter("ignore", FutureWarning)
257-
assert datetime(2015, 1, 2, 0, 0) == datetime(2015, 1, 2, 0, 0)
258-
259-
assert isinstance(datetime(2015, 1, 2, 0, 0), datetime)
260-
261-
262-
def test_sparsearray():
263-
import warnings
264-
265-
with warnings.catch_warnings():
266-
warnings.simplefilter("ignore", FutureWarning)
267-
assert isinstance(pd.array([1, 2, 3], dtype="Sparse"), pd.SparseArray)
268-
269-
270-
def test_np():
271-
import warnings
272-
273-
import numpy as np
274-
275-
with warnings.catch_warnings():
276-
warnings.simplefilter("ignore", FutureWarning)
277-
assert (pd.np.arange(0, 10) == np.arange(0, 10)).all()
278-
279-
280243
class TestApi(Base):
281244
allowed = ["types", "extensions", "indexers", "interchange"]
282245

pandas/tests/arrays/sparse/test_arithmetics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
@pytest.fixture(params=["integer", "block"])
1515
def kind(request):
16-
"""kind kwarg to pass to SparseArray/SparseSeries"""
16+
"""kind kwarg to pass to SparseArray"""
1717
return request.param
1818

1919

0 commit comments

Comments
 (0)