Skip to content

Commit 073710f

Browse files
authored
DEPR: maybe_infer_ndim (#61901)
1 parent 4045d48 commit 073710f

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ Other Deprecations
457457
- Deprecated :meth:`.DataFrameGroupby.corrwith` (:issue:`57158`)
458458
- Deprecated :meth:`Timestamp.utcfromtimestamp`, use ``Timestamp.fromtimestamp(ts, "UTC")`` instead (:issue:`56680`)
459459
- Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`)
460+
- Deprecated ``pd.core.internals.api.maybe_infer_ndim`` (:issue:`40226`)
460461
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.all`, :meth:`DataFrame.min`, :meth:`DataFrame.max`, :meth:`DataFrame.sum`, :meth:`DataFrame.prod`, :meth:`DataFrame.mean`, :meth:`DataFrame.median`, :meth:`DataFrame.sem`, :meth:`DataFrame.var`, :meth:`DataFrame.std`, :meth:`DataFrame.skew`, :meth:`DataFrame.kurt`, :meth:`Series.all`, :meth:`Series.min`, :meth:`Series.max`, :meth:`Series.sum`, :meth:`Series.prod`, :meth:`Series.mean`, :meth:`Series.median`, :meth:`Series.sem`, :meth:`Series.var`, :meth:`Series.std`, :meth:`Series.skew`, and :meth:`Series.kurt`. (:issue:`57087`)
461462
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
462463
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)

pandas/_libs/internals.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,9 @@ cdef class Block:
709709
self.ndim = state[2]
710710
else:
711711
# older pickle
712-
from pandas.core.internals.api import maybe_infer_ndim
712+
from pandas.core.internals.api import _maybe_infer_ndim
713713

714-
ndim = maybe_infer_ndim(self.values, self.mgr_locs)
714+
ndim = _maybe_infer_ndim(self.values, self.mgr_locs)
715715
self.ndim = ndim
716716

717717
cpdef Block slice_block_rows(self, slice slicer):

pandas/core/internals/api.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def make_block(
136136
if not isinstance(placement, BlockPlacement):
137137
placement = BlockPlacement(placement)
138138

139-
ndim = maybe_infer_ndim(values, placement, ndim)
139+
ndim = _maybe_infer_ndim(values, placement, ndim)
140140
if isinstance(values.dtype, (PeriodDtype, DatetimeTZDtype)):
141141
# GH#41168 ensure we can pass 1D dt64tz values
142142
# More generally, any EA dtype that isn't is_1d_only_ea_dtype
@@ -148,7 +148,7 @@ def make_block(
148148
return klass(values, ndim=ndim, placement=placement)
149149

150150

151-
def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
151+
def _maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
152152
"""
153153
If `ndim` is not provided, infer it from placement and values.
154154
"""
@@ -162,3 +162,15 @@ def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int
162162
else:
163163
ndim = values.ndim
164164
return ndim
165+
166+
167+
def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
168+
"""
169+
If `ndim` is not provided, infer it from placement and values.
170+
"""
171+
warnings.warn(
172+
"maybe_infer_ndim is deprecated and will be removed in a future version.",
173+
DeprecationWarning,
174+
stacklevel=2,
175+
)
176+
return _maybe_infer_ndim(values, placement, ndim)

pandas/tests/internals/test_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ def test_create_block_manager_from_blocks_deprecated():
7979
internals.create_block_manager_from_blocks
8080

8181

82+
def test_maybe_infer_ndim_deprecated():
83+
# GH#40226
84+
msg = "maybe_infer_ndim is deprecated and will be removed in a future version."
85+
arr = np.arange(5)
86+
bp = pd._libs.internals.BlockPlacement([1])
87+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
88+
internals.api.maybe_infer_ndim(arr, bp, 1)
89+
90+
8291
def test_create_dataframe_from_blocks(float_frame):
8392
block = float_frame._mgr.blocks[0]
8493
index = float_frame.index.copy()

0 commit comments

Comments
 (0)