Skip to content

DEPR: maybe_infer_ndim #61901

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 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ Other Deprecations
- Deprecated :meth:`.DataFrameGroupby.corrwith` (:issue:`57158`)
- Deprecated :meth:`Timestamp.utcfromtimestamp`, use ``Timestamp.fromtimestamp(ts, "UTC")`` instead (:issue:`56680`)
- Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`)
- Deprecated ``pd.core.internals.api.maybe_infer_ndim`` (:issue:`40226`)
- 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`)
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ cdef class Block:
self.ndim = state[2]
else:
# older pickle
from pandas.core.internals.api import maybe_infer_ndim
from pandas.core.internals.api import _maybe_infer_ndim

ndim = maybe_infer_ndim(self.values, self.mgr_locs)
ndim = _maybe_infer_ndim(self.values, self.mgr_locs)
self.ndim = ndim

cpdef Block slice_block_rows(self, slice slicer):
Expand Down
16 changes: 14 additions & 2 deletions pandas/core/internals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def make_block(
if not isinstance(placement, BlockPlacement):
placement = BlockPlacement(placement)

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


def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
def _maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
"""
If `ndim` is not provided, infer it from placement and values.
"""
Expand All @@ -162,3 +162,15 @@ def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int
else:
ndim = values.ndim
return ndim


def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int:
"""
If `ndim` is not provided, infer it from placement and values.
"""
warnings.warn(
"maybe_infer_ndim is deprecated and will be removed in a future version.",
DeprecationWarning,
stacklevel=2,
)
return _maybe_infer_ndim(values, placement, ndim)
9 changes: 9 additions & 0 deletions pandas/tests/internals/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ def test_create_block_manager_from_blocks_deprecated():
internals.create_block_manager_from_blocks


def test_maybe_infer_ndim_deprecated():
# GH#40226
msg = "maybe_infer_ndim is deprecated and will be removed in a future version."
arr = np.arange(5)
bp = pd._libs.internals.BlockPlacement([1])
with tm.assert_produces_warning(DeprecationWarning, match=msg):
internals.api.maybe_infer_ndim(arr, bp, 1)


def test_create_dataframe_from_blocks(float_frame):
block = float_frame._mgr.blocks[0]
index = float_frame.index.copy()
Expand Down
Loading