Skip to content

Commit

Permalink
Backport PR #56481: Revert "DEPR: make_block (#56422)"
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored and meeseeksmachine committed Jan 10, 2024
1 parent 922a671 commit fc3d938
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 35 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ Other Deprecations
- Changed :meth:`Timedelta.resolution_string` to return ``h``, ``min``, ``s``, ``ms``, ``us``, and ``ns`` instead of ``H``, ``T``, ``S``, ``L``, ``U``, and ``N``, for compatibility with respective deprecations in frequency aliases (:issue:`52536`)
- Deprecated :attr:`offsets.Day.delta`, :attr:`offsets.Hour.delta`, :attr:`offsets.Minute.delta`, :attr:`offsets.Second.delta`, :attr:`offsets.Milli.delta`, :attr:`offsets.Micro.delta`, :attr:`offsets.Nano.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`)
- Deprecated :func:`pandas.api.types.is_interval` and :func:`pandas.api.types.is_period`, use ``isinstance(obj, pd.Interval)`` and ``isinstance(obj, pd.Period)`` instead (:issue:`55264`)
- Deprecated :func:`pd.core.internals.api.make_block`, use public APIs instead (:issue:`40226`)
- Deprecated :func:`read_gbq` and :meth:`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`)
- Deprecated :meth:`.DataFrameGroupBy.fillna` and :meth:`.SeriesGroupBy.fillna`; use :meth:`.DataFrameGroupBy.ffill`, :meth:`.DataFrameGroupBy.bfill` for forward and backward filling or :meth:`.DataFrame.fillna` to fill with a single value (or the Series equivalents) (:issue:`55718`)
- Deprecated :meth:`DateOffset.is_anchored`, use ``obj.n == 1`` for non-Tick subclasses (for Tick this was always False) (:issue:`55388`)
Expand Down Expand Up @@ -722,6 +721,7 @@ Other Deprecations
- Deprecated the extension test classes ``BaseNoReduceTests``, ``BaseBooleanReduceTests``, and ``BaseNumericReduceTests``, use ``BaseReduceTests`` instead (:issue:`54663`)
- Deprecated the option ``mode.data_manager`` and the ``ArrayManager``; only the ``BlockManager`` will be available in future versions (:issue:`55043`)
- Deprecated the previous implementation of :class:`DataFrame.stack`; specify ``future_stack=True`` to adopt the future version (:issue:`53515`)
-

.. ---------------------------------------------------------------------------
.. _whatsnew_220.performance:
Expand Down
11 changes: 1 addition & 10 deletions pandas/core/internals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING
import warnings

import numpy as np

from pandas._libs.internals import BlockPlacement
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import pandas_dtype
from pandas.core.dtypes.dtypes import (
Expand Down Expand Up @@ -52,14 +50,6 @@ def make_block(
- Block.make_block_same_class
- Block.__init__
"""
warnings.warn(
# GH#40226
"make_block is deprecated and will be removed in a future version. "
"Use public APIs instead.",
DeprecationWarning,
stacklevel=find_stack_level(),
)

if dtype is not None:
dtype = pandas_dtype(dtype)

Expand Down Expand Up @@ -123,6 +113,7 @@ def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int

def __getattr__(name: str):
# GH#55139
import warnings

if name in [
"Block",
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/internals/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def test_deprecations(name):
def test_make_block_2d_with_dti():
# GH#41168
dti = pd.date_range("2012", periods=3, tz="UTC")
msg = "make_block is deprecated"
with tm.assert_produces_warning(DeprecationWarning, match=msg):
blk = api.make_block(dti, placement=[0])
blk = api.make_block(dti, placement=[0])

assert blk.shape == (1, 3)
assert blk.values.shape == (1, 3)
Expand Down
20 changes: 6 additions & 14 deletions pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,11 +1383,9 @@ def test_validate_ndim():
values = np.array([1.0, 2.0])
placement = BlockPlacement(slice(2))
msg = r"Wrong number of dimensions. values.ndim != ndim \[1 != 2\]"
depr_msg = "make_block is deprecated"

with pytest.raises(ValueError, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=depr_msg):
make_block(values, placement, ndim=2)
make_block(values, placement, ndim=2)


def test_block_shape():
Expand All @@ -1402,29 +1400,23 @@ def test_make_block_no_pandas_array(block_maker):
# https://github.com/pandas-dev/pandas/pull/24866
arr = pd.arrays.NumpyExtensionArray(np.array([1, 2]))

warn = None if block_maker is not make_block else DeprecationWarning
msg = "make_block is deprecated and will be removed in a future version"

# NumpyExtensionArray, no dtype
with tm.assert_produces_warning(warn, match=msg):
result = block_maker(arr, BlockPlacement(slice(len(arr))), ndim=arr.ndim)
result = block_maker(arr, BlockPlacement(slice(len(arr))), ndim=arr.ndim)
assert result.dtype.kind in ["i", "u"]

if block_maker is make_block:
# new_block requires caller to unwrap NumpyExtensionArray
assert result.is_extension is False

# NumpyExtensionArray, NumpyEADtype
with tm.assert_produces_warning(warn, match=msg):
result = block_maker(arr, slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim)
result = block_maker(arr, slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim)
assert result.dtype.kind in ["i", "u"]
assert result.is_extension is False

# new_block no longer taked dtype keyword
# ndarray, NumpyEADtype
with tm.assert_produces_warning(warn, match=msg):
result = block_maker(
arr.to_numpy(), slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim
)
result = block_maker(
arr.to_numpy(), slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim
)
assert result.dtype.kind in ["i", "u"]
assert result.is_extension is False
1 change: 0 additions & 1 deletion pandas/tests/io/parser/common/test_chunksize.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def test_chunks_have_consistent_numerical_type(all_parsers, monkeypatch):
assert result.a.dtype == float


@pytest.mark.filterwarnings("ignore:make_block is deprecated:FutureWarning")
def test_warn_if_chunks_have_mismatched_type(all_parsers):
warning_type = None
parser = all_parsers
Expand Down
9 changes: 3 additions & 6 deletions pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@

from pandas.io.parsers import read_csv

pytestmark = [
pytest.mark.filterwarnings(
"ignore:Passing a BlockManager to DataFrame:DeprecationWarning"
),
pytest.mark.filterwarnings("ignore:make_block is deprecated:DeprecationWarning"),
]
pytestmark = pytest.mark.filterwarnings(
"ignore:Passing a BlockManager to DataFrame:DeprecationWarning"
)

xfail_pyarrow = pytest.mark.usefixtures("pyarrow_xfail")
skip_pyarrow = pytest.mark.usefixtures("pyarrow_skip")
Expand Down

0 comments on commit fc3d938

Please sign in to comment.