Skip to content

Commit dd2bbc9

Browse files
authored
CLN: Remove Series.view/ravel, fastpath (#57319)
1 parent 1aeaf6b commit dd2bbc9

File tree

10 files changed

+8
-263
lines changed

10 files changed

+8
-263
lines changed

doc/redirects.csv

-2
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,6 @@ generated/pandas.Series.ptp,../reference/api/pandas.Series.ptp
11141114
generated/pandas.Series.quantile,../reference/api/pandas.Series.quantile
11151115
generated/pandas.Series.radd,../reference/api/pandas.Series.radd
11161116
generated/pandas.Series.rank,../reference/api/pandas.Series.rank
1117-
generated/pandas.Series.ravel,../reference/api/pandas.Series.ravel
11181117
generated/pandas.Series.rdiv,../reference/api/pandas.Series.rdiv
11191118
generated/pandas.Series.rdivmod,../reference/api/pandas.Series.rdivmod
11201119
generated/pandas.Series.real,../reference/api/pandas.Series.real
@@ -1249,7 +1248,6 @@ generated/pandas.Series.valid,../reference/api/pandas.Series.valid
12491248
generated/pandas.Series.value_counts,../reference/api/pandas.Series.value_counts
12501249
generated/pandas.Series.values,../reference/api/pandas.Series.values
12511250
generated/pandas.Series.var,../reference/api/pandas.Series.var
1252-
generated/pandas.Series.view,../reference/api/pandas.Series.view
12531251
generated/pandas.Series.where,../reference/api/pandas.Series.where
12541252
generated/pandas.Series.xs,../reference/api/pandas.Series.xs
12551253
generated/pandas.set_option,../reference/api/pandas.set_option

doc/source/reference/series.rst

-2
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,8 @@ Reshaping, sorting
236236
Series.unstack
237237
Series.explode
238238
Series.searchsorted
239-
Series.ravel
240239
Series.repeat
241240
Series.squeeze
242-
Series.view
243241

244242
Combining / comparing / joining / merging
245243
-----------------------------------------

doc/source/whatsnew/v3.0.0.rst

+4
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,18 @@ Deprecations
104104
Removal of prior version deprecations/changes
105105
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106106
- All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`)
107+
- Removed ``DataFrame.first`` and ``DataFrame.last`` (:issue:`53710`)
107108
- Removed ``DataFrameGroupBy.grouper`` and ``SeriesGroupBy.grouper`` (:issue:`56521`)
108109
- Removed ``DataFrameGroupby.fillna`` and ``SeriesGroupBy.fillna``` (:issue:`55719`)
110+
- Removed ``Series.ravel`` (:issue:`56053`)
111+
- Removed ``Series.view`` (:issue:`56054`)
109112
- Removed ``axis`` argument from :meth:`DataFrame.groupby`, :meth:`Series.groupby`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.resample`, and :meth:`Series.resample` (:issue:`51203`)
110113
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
111114
- Removed ``pandas.io.sql.execute`` (:issue:`50185`)
112115
- Removed ``read_gbq`` and ``DataFrame.to_gbq``. Use ``pandas_gbq.read_gbq`` and ``pandas_gbq.to_gbq`` instead https://pandas-gbq.readthedocs.io/en/latest/api.html (:issue:`55525`)
113116
- Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`)
114117
- Removed the ``ArrayManager`` (:issue:`55043`)
118+
- Removed the ``fastpath`` argument from the :class:`Series` constructor (:issue:`55466`)
115119
- Removed the ``is_boolean``, ``is_integer``, ``is_floating``, ``holds_integer``, ``is_numeric``, ``is_categorical``, ``is_object``, and ``is_interval`` attributes of :class:`Index` (:issue:`50042`)
116120
- Removed unused arguments ``*args`` and ``**kwargs`` in :class:`Resampler` methods (:issue:`50977`)
117121
- Unrecognized timezones when parsing strings to datetimes now raises a ``ValueError`` (:issue:`51477`)

pandas/core/series.py

+1-133
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,7 @@ def __init__(
385385
dtype: Dtype | None = None,
386386
name=None,
387387
copy: bool | None = None,
388-
fastpath: bool | lib.NoDefault = lib.no_default,
389388
) -> None:
390-
if fastpath is not lib.no_default:
391-
warnings.warn(
392-
"The 'fastpath' keyword in pd.Series is deprecated and will "
393-
"be removed in a future version.",
394-
DeprecationWarning,
395-
stacklevel=find_stack_level(),
396-
)
397-
else:
398-
fastpath = False
399-
400389
allow_mgr = False
401390
if (
402391
isinstance(data, SingleBlockManager)
@@ -417,11 +406,7 @@ def __init__(
417406
data = data.copy(deep=False)
418407
# GH#33357 called with just the SingleBlockManager
419408
NDFrame.__init__(self, data)
420-
if fastpath:
421-
# e.g. from _box_col_values, skip validation of name
422-
object.__setattr__(self, "_name", name)
423-
else:
424-
self.name = name
409+
self.name = name
425410
return
426411

427412
is_pandas_object = isinstance(data, (Series, Index, ExtensionArray))
@@ -435,31 +420,6 @@ def __init__(
435420
if copy is None:
436421
copy = False
437422

438-
# we are called internally, so short-circuit
439-
if fastpath:
440-
# data is a ndarray, index is defined
441-
if not isinstance(data, SingleBlockManager):
442-
data = SingleBlockManager.from_array(data, index)
443-
allow_mgr = True
444-
elif using_copy_on_write() and not copy:
445-
data = data.copy(deep=False)
446-
447-
if not allow_mgr:
448-
warnings.warn(
449-
f"Passing a {type(data).__name__} to {type(self).__name__} "
450-
"is deprecated and will raise in a future version. "
451-
"Use public APIs instead.",
452-
DeprecationWarning,
453-
stacklevel=2,
454-
)
455-
456-
if copy:
457-
data = data.copy()
458-
# skips validation of the name
459-
object.__setattr__(self, "_name", name)
460-
NDFrame.__init__(self, data)
461-
return
462-
463423
if isinstance(data, SingleBlockManager) and using_copy_on_write() and not copy:
464424
data = data.copy(deep=False)
465425

@@ -851,104 +811,12 @@ def _references(self) -> BlockValuesRefs:
851811
def array(self) -> ExtensionArray:
852812
return self._mgr.array_values()
853813

854-
# ops
855-
def ravel(self, order: str = "C") -> ArrayLike:
856-
"""
857-
Return the flattened underlying data as an ndarray or ExtensionArray.
858-
859-
.. deprecated:: 2.2.0
860-
Series.ravel is deprecated. The underlying array is already 1D, so
861-
ravel is not necessary. Use :meth:`to_numpy` for conversion to a numpy
862-
array instead.
863-
864-
Returns
865-
-------
866-
numpy.ndarray or ExtensionArray
867-
Flattened data of the Series.
868-
869-
See Also
870-
--------
871-
numpy.ndarray.ravel : Return a flattened array.
872-
873-
Examples
874-
--------
875-
>>> s = pd.Series([1, 2, 3])
876-
>>> s.ravel() # doctest: +SKIP
877-
array([1, 2, 3])
878-
"""
879-
warnings.warn(
880-
"Series.ravel is deprecated. The underlying array is already 1D, so "
881-
"ravel is not necessary. Use `to_numpy()` for conversion to a numpy "
882-
"array instead.",
883-
FutureWarning,
884-
stacklevel=2,
885-
)
886-
arr = self._values.ravel(order=order)
887-
if isinstance(arr, np.ndarray) and using_copy_on_write():
888-
arr.flags.writeable = False
889-
return arr
890-
891814
def __len__(self) -> int:
892815
"""
893816
Return the length of the Series.
894817
"""
895818
return len(self._mgr)
896819

897-
def view(self, dtype: Dtype | None = None) -> Series:
898-
"""
899-
Create a new view of the Series.
900-
901-
.. deprecated:: 2.2.0
902-
``Series.view`` is deprecated and will be removed in a future version.
903-
Use :meth:`Series.astype` as an alternative to change the dtype.
904-
905-
This function will return a new Series with a view of the same
906-
underlying values in memory, optionally reinterpreted with a new data
907-
type. The new data type must preserve the same size in bytes as to not
908-
cause index misalignment.
909-
910-
Parameters
911-
----------
912-
dtype : data type
913-
Data type object or one of their string representations.
914-
915-
Returns
916-
-------
917-
Series
918-
A new Series object as a view of the same data in memory.
919-
920-
See Also
921-
--------
922-
numpy.ndarray.view : Equivalent numpy function to create a new view of
923-
the same data in memory.
924-
925-
Notes
926-
-----
927-
Series are instantiated with ``dtype=float64`` by default. While
928-
``numpy.ndarray.view()`` will return a view with the same data type as
929-
the original array, ``Series.view()`` (without specified dtype)
930-
will try using ``float64`` and may fail if the original data type size
931-
in bytes is not the same.
932-
933-
Examples
934-
--------
935-
Use ``astype`` to change the dtype instead.
936-
"""
937-
warnings.warn(
938-
"Series.view is deprecated and will be removed in a future version. "
939-
"Use ``astype`` as an alternative to change the dtype.",
940-
FutureWarning,
941-
stacklevel=2,
942-
)
943-
# self.array instead of self._values so we piggyback on NumpyExtensionArray
944-
# implementation
945-
res_values = self.array.view(dtype)
946-
res_ser = self._constructor(res_values, index=self.index, copy=False)
947-
if isinstance(res_ser._mgr, SingleBlockManager):
948-
blk = res_ser._mgr._block
949-
blk.refs.add_reference(blk)
950-
return res_ser.__finalize__(self, method="view")
951-
952820
# ----------------------------------------------------------------------
953821
# NDArray Compat
954822
def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray:

pandas/tests/copy_view/test_array.py

-10
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,6 @@ def test_series_to_numpy(using_copy_on_write):
110110
assert arr.flags.writeable is True
111111

112112

113-
@pytest.mark.parametrize("order", ["F", "C"])
114-
def test_ravel_read_only(using_copy_on_write, order):
115-
ser = Series([1, 2, 3])
116-
with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
117-
arr = ser.ravel(order=order)
118-
if using_copy_on_write:
119-
assert arr.flags.writeable is False
120-
assert np.shares_memory(get_array(ser), arr)
121-
122-
123113
def test_series_array_ea_dtypes(using_copy_on_write):
124114
ser = Series([1, 2, 3], dtype="Int64")
125115
arr = np.asarray(ser, dtype="int64")

pandas/tests/copy_view/test_constructors.py

+2-29
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,13 @@ def test_series_from_series_with_reindex(using_copy_on_write):
9090
assert not result._mgr.blocks[0].refs.has_reference()
9191

9292

93-
@pytest.mark.parametrize("fastpath", [False, True])
9493
@pytest.mark.parametrize("dtype", [None, "int64"])
9594
@pytest.mark.parametrize("idx", [None, pd.RangeIndex(start=0, stop=3, step=1)])
9695
@pytest.mark.parametrize(
9796
"arr", [np.array([1, 2, 3], dtype="int64"), pd.array([1, 2, 3], dtype="Int64")]
9897
)
99-
def test_series_from_array(using_copy_on_write, idx, dtype, fastpath, arr):
100-
if idx is None or dtype is not None:
101-
fastpath = False
102-
msg = "The 'fastpath' keyword in pd.Series is deprecated"
103-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
104-
ser = Series(arr, dtype=dtype, index=idx, fastpath=fastpath)
98+
def test_series_from_array(using_copy_on_write, idx, dtype, arr):
99+
ser = Series(arr, dtype=dtype, index=idx)
105100
ser_orig = ser.copy()
106101
data = getattr(arr, "_data", arr)
107102
if using_copy_on_write:
@@ -153,28 +148,6 @@ def test_series_from_index_different_dtypes(using_copy_on_write):
153148
assert ser._mgr._has_no_reference(0)
154149

155150

156-
@pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning")
157-
@pytest.mark.parametrize("fastpath", [False, True])
158-
@pytest.mark.parametrize("dtype", [None, "int64"])
159-
@pytest.mark.parametrize("idx", [None, pd.RangeIndex(start=0, stop=3, step=1)])
160-
def test_series_from_block_manager(using_copy_on_write, idx, dtype, fastpath):
161-
ser = Series([1, 2, 3], dtype="int64")
162-
ser_orig = ser.copy()
163-
msg = "The 'fastpath' keyword in pd.Series is deprecated"
164-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
165-
ser2 = Series(ser._mgr, dtype=dtype, fastpath=fastpath, index=idx)
166-
assert np.shares_memory(get_array(ser), get_array(ser2))
167-
if using_copy_on_write:
168-
assert not ser2._mgr._has_no_reference(0)
169-
170-
ser2.iloc[0] = 100
171-
if using_copy_on_write:
172-
tm.assert_series_equal(ser, ser_orig)
173-
else:
174-
expected = Series([100, 2, 3])
175-
tm.assert_series_equal(ser, expected)
176-
177-
178151
def test_series_from_block_manager_different_dtype(using_copy_on_write):
179152
ser = Series([1, 2, 3], dtype="int64")
180153
msg = "Passing a SingleBlockManager to Series"

pandas/tests/copy_view/test_methods.py

-19
Original file line numberDiff line numberDiff line change
@@ -1859,25 +1859,6 @@ def test_count_read_only_array():
18591859
tm.assert_series_equal(result, expected)
18601860

18611861

1862-
def test_series_view(using_copy_on_write):
1863-
ser = Series([1, 2, 3])
1864-
ser_orig = ser.copy()
1865-
1866-
with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
1867-
ser2 = ser.view()
1868-
assert np.shares_memory(get_array(ser), get_array(ser2))
1869-
if using_copy_on_write:
1870-
assert not ser2._mgr._has_no_reference(0)
1871-
1872-
ser2.iloc[0] = 100
1873-
1874-
if using_copy_on_write:
1875-
tm.assert_series_equal(ser_orig, ser)
1876-
else:
1877-
expected = Series([100, 2, 3])
1878-
tm.assert_series_equal(ser, expected)
1879-
1880-
18811862
def test_insert_series(using_copy_on_write):
18821863
df = DataFrame({"a": [1, 2, 3]})
18831864
ser = Series([1, 2, 3])

pandas/tests/frame/indexing/test_where.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -761,15 +761,13 @@ def test_where_interval_fullop_downcast(self, frame_or_series):
761761
"timedelta64[ns]",
762762
"datetime64[ns]",
763763
"datetime64[ns, Asia/Tokyo]",
764-
"Period[D]",
765764
],
766765
)
767766
def test_where_datetimelike_noop(self, dtype):
768767
# GH#45135, analogue to GH#44181 for Period don't raise on no-op
769768
# For td64/dt64/dt64tz we already don't raise, but also are
770769
# checking that we don't unnecessarily upcast to object.
771-
with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
772-
ser = Series(np.arange(3) * 10**9, dtype=np.int64).view(dtype)
770+
ser = Series(np.arange(3) * 10**9, dtype=np.int64).astype(dtype)
773771
df = ser.to_frame()
774772
mask = np.array([False, False, False])
775773

pandas/tests/series/methods/test_view.py

-58
This file was deleted.

pandas/tests/series/test_api.py

-7
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ def test_ndarray_compat_like_func(self):
138138
expected = Series(1, index=range(10), dtype="float64")
139139
tm.assert_series_equal(result, expected)
140140

141-
def test_ndarray_compat_ravel(self):
142-
# ravel
143-
s = Series(np.random.default_rng(2).standard_normal(10))
144-
with tm.assert_produces_warning(FutureWarning, match="ravel is deprecated"):
145-
result = s.ravel(order="F")
146-
tm.assert_almost_equal(result, s.values.ravel(order="F"))
147-
148141
def test_empty_method(self):
149142
s_empty = Series(dtype=object)
150143
assert s_empty.empty

0 commit comments

Comments
 (0)