Skip to content
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

CLN: enforce the deprecation of exposing blocks in core.internals #58467

Merged
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 @@ -250,6 +250,7 @@ Removal of prior version deprecations/changes
- Enforced deprecation of :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`57820`)
- Enforced deprecation of :meth:`offsets.Tick.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`)
- Enforced deprecation of ``axis=None`` acting the same as ``axis=0`` in the DataFrame reductions ``sum``, ``prod``, ``std``, ``var``, and ``sem``, passing ``axis=None`` will now reduce over both axes; this is particularly the case when doing e.g. ``numpy.sum(df)`` (:issue:`21597`)
- Enforced deprecation of ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock`` (:issue:`58467`)
- Enforced deprecation of non-standard (``np.ndarray``, :class:`ExtensionArray`, :class:`Index`, or :class:`Series`) argument to :func:`api.extensions.take` (:issue:`52981`)
- Enforced deprecation of parsing system timezone strings to ``tzlocal``, which depended on system timezone, pass the 'tz' keyword instead (:issue:`50791`)
- Enforced deprecation of passing a dictionary to :meth:`SeriesGroupBy.agg` (:issue:`52268`)
Expand Down
50 changes: 0 additions & 50 deletions pandas/core/internals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,8 @@
)

__all__ = [
"Block",
"DatetimeTZBlock",
"ExtensionBlock",
"make_block",
"BlockManager",
"SingleBlockManager",
"concatenate_managers",
]


def __getattr__(name: str):
# GH#55139
import warnings
twoertwein marked this conversation as resolved.
Show resolved Hide resolved

if name == "create_block_manager_from_blocks":
# GH#33892
warnings.warn(
f"{name} is deprecated and will be removed in a future version. "
"Use public APIs instead.",
DeprecationWarning,
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
# on hard-coding stacklevel
stacklevel=2,
)
from pandas.core.internals.managers import create_block_manager_from_blocks

return create_block_manager_from_blocks

if name in [
"Block",
"ExtensionBlock",
"DatetimeTZBlock",
]:
warnings.warn(
f"{name} is deprecated and will be removed in a future version. "
"Use public APIs instead.",
DeprecationWarning,
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
# on hard-coding stacklevel
stacklevel=2,
)
if name == "DatetimeTZBlock":
from pandas.core.internals.blocks import DatetimeTZBlock

return DatetimeTZBlock
elif name == "ExtensionBlock":
from pandas.core.internals.blocks import ExtensionBlock

return ExtensionBlock
else:
from pandas.core.internals.blocks import Block

return Block

raise AttributeError(f"module 'pandas.core.internals' has no attribute '{name}'")
3 changes: 2 additions & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
npt,
)

from pandas.core.internals import Block
from pandas.core.internals.blocks import Block


# versioning attribute
_version = "0.15.2"
Expand Down
27 changes: 0 additions & 27 deletions pandas/tests/internals/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ def test_namespace():
assert set(result) == set(expected + modules)


@pytest.mark.parametrize(
"name",
[
"Block",
"ExtensionBlock",
"DatetimeTZBlock",
],
)
def test_deprecations(name):
# GH#55139
msg = f"{name} is deprecated.* Use public APIs instead"
with tm.assert_produces_warning(DeprecationWarning, match=msg):
getattr(internals, name)


def test_make_block_2d_with_dti():
# GH#41168
dti = pd.date_range("2012", periods=3, tz="UTC")
Expand All @@ -65,18 +50,6 @@ def test_make_block_2d_with_dti():
assert blk.values.shape == (1, 3)


def test_create_block_manager_from_blocks_deprecated():
# GH#33892
# If they must, downstream packages should get this from internals.api,
# not internals.
msg = (
"create_block_manager_from_blocks is deprecated and will be "
"removed in a future version. Use public APIs instead"
)
with tm.assert_produces_warning(DeprecationWarning, match=msg):
internals.create_block_manager_from_blocks


def test_create_dataframe_from_blocks(float_frame):
block = float_frame._mgr.blocks[0]
index = float_frame.index.copy()
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ def test_read_empty_array(self, pa, dtype):
"value": pd.array([], dtype=dtype),
}
)
if Version(pyarrow.__version__) == "10.0.1":
pytest.skip("skip the pyarrow version '10.0.1'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if Version(pyarrow.__version__) == "10.0.1":
pytest.skip("skip the pyarrow version '10.0.1'")
pytest.importorskip("pyarrow", "10.0.1")

And similar below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your help. It seems that it doesn't work when using pytest.importorskip("pyarrow", "10.0.1"), but it works properly with pytest.importorskip("pyarrow", "11.0.0")

# GH 45694
expected = None
if dtype == "float":
Expand All @@ -672,6 +674,9 @@ class TestParquetPyArrow(Base):
def test_basic(self, pa, df_full):
df = df_full

if Version(pyarrow.__version__) == "10.0.1":
pytest.skip("skip the pyarrow version '10.0.1'")

# additional supported types for pyarrow
dti = pd.date_range("20130101", periods=3, tz="Europe/Brussels")
dti = dti._with_freq(None) # freq doesn't round-trip
Expand Down Expand Up @@ -938,6 +943,8 @@ def test_timestamp_nanoseconds(self, pa):
check_round_trip(df, pa, write_kwargs={"version": ver})

def test_timezone_aware_index(self, request, pa, timezone_aware_date_list):
if Version(pyarrow.__version__) == "10.0.1":
pytest.skip("skip the pyarrow version '10.0.1'")
if timezone_aware_date_list.tzinfo != datetime.timezone.utc:
request.applymarker(
pytest.mark.xfail(
Expand Down
Loading