8000 CLN: Deprecate pandas.SparseArray for pandas.arrays.SparseArray by Dr-Irv · Pull Request #30656 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CLN: Deprecate pandas.SparseArray for pandas.arrays.SparseArray #30656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
DOC: Deprecate pandas.SparseArray
  • Loading branch information
Dr-Irv committed Jan 3, 2020
commit 23696b248c22aa044b566bce37ddcd9878f0f9a6
2 changes: 1 addition & 1 deletion doc/source/development/contributing_docstring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ DataFrame:
* DataFrame
* pandas.Index
* pandas.Categorical
* pandas.SparseArray
* pandas.arrays.SparseArray

If the exact type is not relevant, but must be compatible with a numpy
array, array-like can be specified. If Any type that can be iterated is
Expand Down
2 changes: 1 addition & 1 deletion doc/source/getting_started/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ documentation sections for more on each type.
| period | :class:`PeriodDtype` | :class:`Period` | :class:`arrays.PeriodArray` | ``'period[<freq>]'``, | :ref:`timeseries.periods` |
| (time spans) | | | | ``'Period[<freq>]'`` | |
+-------------------+---------------------------+--------------------+-------------------------------+-----------------------------------------+-------------------------------+
| sparse | :class:`SparseDtype` | (none) | :class:`SparseArray` | ``'Sparse'``, ``'Sparse[int]'``, | :ref:`sparse` |
| sparse | :class:`SparseDtype` | (none) | :class:`arrays.SparseArray` | ``'Sparse'``, ``'Sparse[int]'``, | :ref:`sparse` |
| | | | | ``'Sparse[float]'`` | |
+-------------------+---------------------------+--------------------+-------------------------------+-----------------------------------------+-------------------------------+
| intervals | :class:`IntervalDtype` | :class:`Interval` | :class:`arrays.IntervalArray` | ``'interval'``, ``'Interval'``, | :ref:`advanced.intervalindex` |
Expand Down
2 changes: 1 addition & 1 deletion doc/source/getting_started/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ implementation takes precedence and a Serie 8000 s is returned.
np.maximum(ser, idx)

NumPy ufuncs are safe to apply to :class:`Series` backed by non-ndarray arrays,
for example :class:`SparseArray` (see :ref:`sparse.calculation`). If possible,
for example :class:`arrays.SparseArray` (see :ref:`sparse.calculation`). If possible,
the ufunc is applied without converting the underlying data to an ndarray.

Console display
Expand Down
4 changes: 2 additions & 2 deletions doc/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,13 @@ Sparse data
-----------

Data where a single value is repeated many times (e.g. ``0`` or ``NaN``) may
be stored efficiently as a :class:`SparseArray`.
be stored efficiently as a :class:`arrays.SparseArray`.

.. autosummary::
:toctree: api/
:template: autosummary/class_without_autosummary.rst

SparseArray
arrays.SparseArray

.. autosummary::
:toctree: api/
Expand Down
16 changes: 8 additions & 8 deletions doc/source/user_guide/sparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ can be chosen, including 0) is omitted. The compressed values are not actually s

arr = np.random.randn(10)
arr[2:-2] = np.nan
ts = pd.Series(pd.SparseArray(arr))
ts = pd.Series(pd.arrays.SparseArray(arr))
ts

Notice the dtype, ``Sparse[float64, nan]``. The ``nan`` means that elements in the
Expand Down Expand Up @@ -51,7 +51,7 @@ identical to their dense counterparts.
SparseArray
-----------

:class:`SparseArray` is a :class:`~pandas.api.extensions.ExtensionArray`
:class:`arrays.SparseArray` is a :class:`~pandas.api.extensions.ExtensionArray`
for storing an array of sparse values (see :ref:`basics.dtypes` for more
on extension arrays). It is a 1-dimensional ndarray-like object storing
only values distinct from the ``fill_value``:
Expand All @@ -61,7 +61,7 @@ only values distinct from the ``fill_value``:
arr = np.random.randn(10)
arr[2:5] = np.nan
arr[7:8] = np.nan
sparr = pd.SparseArray(arr)
sparr = pd.arrays.SparseArray(arr)
sparr

A sparse array can be converted to a regular (dense) ndarray with :meth:`numpy.asarray`
Expand Down Expand Up @@ -144,7 +144,7 @@ to ``SparseArray`` and get a ``SparseArray`` as a result.

.. ipython:: python

arr = pd.SparseArray([1., np.nan, np.nan, -2., np.nan])
arr = pd.arrays.SparseArray([1., np.nan, np.nan, -2., np.nan])
np.abs(arr)


Expand All @@ -153,7 +153,7 @@ the correct dense result.

.. ipython:: python

arr = pd.SparseArray([1., -1, -1, -2., -1], fill_value=-1)
arr = pd.arrays.SparseArray([1., -1, -1, -2., -1], fill_value=-1)
np.abs(arr)
np.abs(arr).to_dense()

Expand Down Expand Up @@ -194,7 +194,7 @@ From an array-like, use the regular :class:`Series` or
.. ipython:: python

# New way
pd.DataFrame({" 67E6 A": pd.SparseArray([0, 1])})
pd.DataFrame({"A": pd.arrays.SparseArray([0, 1])})

From a SciPy sparse matrix, use :meth:`DataFrame.sparse.from_spmatrix`,

Expand Down Expand Up @@ -256,10 +256,10 @@ Instead, you'll need to ensure that the values being assigned are sparse

.. ipython:: python

df = pd.DataFrame({"A": pd.SparseArray([0, 1])})
df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1])})
df['B'] = [0, 0] # remains dense
df['B'].dtype
df['B'] = pd.SparseArray([0, 0])
df['B'] = pd.arrays.SparseArray([0, 0])
df['B'].dtype

The ``SparseDataFrame.default_kind`` and ``SparseDataFrame.default_fill_value`` attributes
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ Deprecations
it is recommended to use ``json_normalize`` as :func:`pandas.json_normalize` instead (:issue:`27586`).
- :meth:`DataFrame.to_stata`, :meth:`DataFrame.to_feather`, and :meth:`DataFrame.to_parquet` argument "fname" is deprecated, use "path" instead (:issue:`23574`)
- The deprecated internal attributes ``_start``, ``_stop`` and ``_step`` of :class:`RangeIndex` now raise a ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`26581`)
- ``pandas.SparseArray`` has been deprecated. Use ``pandas.arrays.SparseArray`` (:class:`arrays.SparseArray`) instead. (:issue:`30642`)

**Selecting Columns from a Grouped DataFrame**

Expand Down
0