Skip to content

Commit 66a54a3

Browse files
authored
DEPR: Series constructor fastpath keyword (#55466)
1 parent e22bfb3 commit 66a54a3

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

asv_bench/benchmarks/series_methods.py

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ def time_constructor_dict(self):
2828
def time_constructor_no_data(self):
2929
Series(data=None, index=self.idx)
3030

31-
def time_constructor_fastpath(self):
32-
Series(self.array, index=self.idx2, name="name", fastpath=True)
33-
3431

3532
class ToFrame:
3633
params = [["int64", "datetime64[ns]", "category", "Int64"], [None, "foo"]]

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ Other Deprecations
256256
- Deprecated strings ``H``, ``S``, ``U``, and ``N`` denoting units in :func:`to_timedelta` (:issue:`52536`)
257257
- Deprecated strings ``H``, ``T``, ``S``, ``L``, ``U``, and ``N`` denoting units in :class:`Timedelta` (:issue:`52536`)
258258
- Deprecated strings ``T``, ``S``, ``L``, ``U``, and ``N`` denoting frequencies in :class:`Minute`, :class:`Second`, :class:`Milli`, :class:`Micro`, :class:`Nano` (:issue:`52536`)
259+
- Deprecated the ``fastpath`` keyword in the :class:`Series` constructor (:issue:`20110`)
259260
- Deprecated the extension test classes ``BaseNoReduceTests``, ``BaseBooleanReduceTests``, and ``BaseNumericReduceTests``, use ``BaseReduceTests`` instead (:issue:`54663`)
260261
- Deprecated the option ``mode.data_manager`` and the ``ArrayManager``; only the ``BlockManager`` will be available in future versions (:issue:`55043`)
261262
- Deprecating downcasting the results of :meth:`DataFrame.fillna`, :meth:`Series.fillna`, :meth:`DataFrame.ffill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill`, :meth:`Series.bfill` in object-dtype cases. To opt in to the future version, use ``pd.set_option("future.no_silent_downcasting", True)`` (:issue:`54261`)

pandas/core/frame.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -5168,12 +5168,7 @@ def _sanitize_column(self, value) -> tuple[ArrayLike, BlockValuesRefs | None]:
51685168

51695169
@property
51705170
def _series(self):
5171-
return {
5172-
item: Series(
5173-
self._mgr.iget(idx), index=self.index, name=item, fastpath=True
5174-
)
5175-
for idx, item in enumerate(self.columns)
5176-
}
5171+
return {item: self._ixs(idx, axis=1) for idx, item in enumerate(self.columns)}
51775172

51785173
# ----------------------------------------------------------------------
51795174
# Reindexing and alignment

pandas/core/series.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,18 @@ def __init__(
374374
dtype: Dtype | None = None,
375375
name=None,
376376
copy: bool | None = None,
377-
fastpath: bool = False,
377+
fastpath: bool | lib.NoDefault = lib.no_default,
378378
) -> None:
379+
if fastpath is not lib.no_default:
380+
warnings.warn(
381+
"The 'fastpath' keyword in pd.Series is deprecated and will "
382+
"be removed in a future version.",
383+
DeprecationWarning,
384+
stacklevel=find_stack_level(),
385+
)
386+
else:
387+
fastpath = False
388+
379389
if (
380390
isinstance(data, (SingleBlockManager, SingleArrayManager))
381391
and index is None
@@ -1009,7 +1019,8 @@ def _slice(self, slobj: slice, axis: AxisInt = 0) -> Series:
10091019
# axis kwarg is retained for compat with NDFrame method
10101020
# _slice is *always* positional
10111021
mgr = self._mgr.get_slice(slobj, axis=axis)
1012-
out = self._constructor(mgr, fastpath=True)
1022+
out = self._constructor_from_mgr(mgr, axes=mgr.axes)
1023+
out._name = self._name
10131024
return out.__finalize__(self)
10141025

10151026
def __getitem__(self, key):

pandas/tests/copy_view/test_constructors.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def test_series_from_series_with_reindex(using_copy_on_write):
9999
def test_series_from_array(using_copy_on_write, idx, dtype, fastpath, arr):
100100
if idx is None or dtype is not None:
101101
fastpath = False
102-
ser = Series(arr, dtype=dtype, index=idx, fastpath=fastpath)
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)
103105
ser_orig = ser.copy()
104106
data = getattr(arr, "_data", arr)
105107
if using_copy_on_write:
@@ -157,7 +159,9 @@ def test_series_from_index_different_dtypes(using_copy_on_write):
157159
def test_series_from_block_manager(using_copy_on_write, idx, dtype, fastpath):
158160
ser = Series([1, 2, 3], dtype="int64")
159161
ser_orig = ser.copy()
160-
ser2 = Series(ser._mgr, dtype=dtype, fastpath=fastpath, index=idx)
162+
msg = "The 'fastpath' keyword in pd.Series is deprecated"
163+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
164+
ser2 = Series(ser._mgr, dtype=dtype, fastpath=fastpath, index=idx)
161165
assert np.shares_memory(get_array(ser), get_array(ser2))
162166
if using_copy_on_write:
163167
assert not ser2._mgr._has_no_reference(0)

0 commit comments

Comments
 (0)