Skip to content

Commit 02f2230

Browse files
jbrockmendelphofl
authored andcommitted
DEPR: internals (pandas-dev#49392)
* DEPR: internals * bump fastparquet minimum
1 parent fd33e78 commit 02f2230

File tree

13 files changed

+12
-127
lines changed

13 files changed

+12
-127
lines changed

ci/deps/actions-38-minimum_versions.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
- blosc=1.21.0
2626
- bottleneck=1.3.2
2727
- brotlipy=0.7.0
28-
- fastparquet=0.4.0
28+
- fastparquet=0.6.3
2929
- fsspec=2021.07.0
3030
- html5lib=1.1
3131
- hypothesis=6.13.0

doc/source/whatsnew/v2.0.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Optional libraries below the lowest tested version may still work, but are not c
124124
+=================+=================+=========+
125125
| pyarrow | 6.0.0 | X |
126126
+-----------------+-----------------+---------+
127+
| fastparquet | 0.6.3 | X |
128+
+-----------------+-----------------+---------+
127129

128130
See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more.
129131

@@ -158,6 +160,7 @@ Deprecations
158160

159161
Removal of prior version deprecations/changes
160162
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163+
- Removed deprecated :class:`CategoricalBlock`, :meth:`Block.is_categorical`, require datetime64 and timedelta64 values to be wrapped in :class:`DatetimeArray` or :class:`TimedeltaArray` before passing to :meth:`Block.make_block_same_class`, require ``DatetimeTZBlock.values`` to have the correct ndim when passing to the :class:`BlockManager` constructor, and removed the "fastpath" keyword from the :class:`SingleBlockManager` constructor (:issue:`40226`, :issue:`40571`)
161164
- Removed deprecated module ``pandas.core.index`` (:issue:`30193`)
162165
- Removed deprecated :meth:`Categorical.to_dense`, use ``np.asarray(cat)`` instead (:issue:`32639`)
163166
- Removed deprecated :meth:`Categorical.take_nd` (:issue:`27745`)

pandas/compat/_optional.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"blosc": "1.21.0",
1717
"bottleneck": "1.3.2",
1818
"brotli": "0.7.0",
19-
"fastparquet": "0.4.0",
19+
"fastparquet": "0.6.3",
2020
"fsspec": "2021.07.0",
2121
"html5lib": "1.1",
2222
"hypothesis": "6.13.0",

pandas/core/internals/__init__.py

-19
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,3 @@
3838
# this is preserved here for downstream compatibility (GH-33892)
3939
"create_block_manager_from_blocks",
4040
]
41-
42-
43-
def __getattr__(name: str):
44-
import warnings
45-
46-
from pandas.util._exceptions import find_stack_level
47-
48-
if name == "CategoricalBlock":
49-
warnings.warn(
50-
"CategoricalBlock is deprecated and will be removed in a future version. "
51-
"Use ExtensionBlock instead.",
52-
DeprecationWarning,
53-
stacklevel=find_stack_level(),
54-
)
55-
from pandas.core.internals.blocks import CategoricalBlock
56-
57-
return CategoricalBlock
58-
59-
raise AttributeError(f"module 'pandas.core.internals' has no attribute '{name}'")

pandas/core/internals/blocks.py

+4-43
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
is_string_dtype,
6060
)
6161
from pandas.core.dtypes.dtypes import (
62-
CategoricalDtype,
6362
ExtensionDtype,
6463
PandasDtype,
6564
PeriodDtype,
@@ -175,18 +174,6 @@ def _can_hold_na(self) -> bool:
175174
return dtype.kind not in ["b", "i", "u"]
176175
return dtype._can_hold_na
177176

178-
@final
179-
@cache_readonly
180-
def is_categorical(self) -> bool:
181-
warnings.warn(
182-
"Block.is_categorical is deprecated and will be removed in a "
183-
"future version. Use isinstance(block.values, Categorical) "
184-
"instead. See https://github.com/pandas-dev/pandas/issues/40226",
185-
DeprecationWarning,
186-
stacklevel=find_stack_level(),
187-
)
188-
return isinstance(self.values, Categorical)
189-
190177
@final
191178
@property
192179
def is_bool(self) -> bool:
@@ -240,24 +227,11 @@ def make_block_same_class(
240227
self, values, placement: BlockPlacement | None = None
241228
) -> Block:
242229
"""Wrap given values in a block of same type as self."""
230+
# Pre-2.0 we called ensure_wrapped_if_datetimelike because fastparquet
231+
# relied on it, as of 2.0 the caller is responsible for this.
243232
if placement is None:
244233
placement = self._mgr_locs
245234

246-
if values.dtype.kind in ["m", "M"]:
247-
248-
new_values = ensure_wrapped_if_datetimelike(values)
249-
if new_values is not values:
250-
# TODO(2.0): remove once fastparquet has stopped relying on it
251-
warnings.warn(
252-
"In a future version, Block.make_block_same_class will "
253-
"assume that datetime64 and timedelta64 ndarrays have "
254-
"already been cast to DatetimeArray and TimedeltaArray, "
255-
"respectively.",
256-
DeprecationWarning,
257-
stacklevel=find_stack_level(),
258-
)
259-
values = new_values
260-
261235
# We assume maybe_coerce_values has already been called
262236
return type(self)(values, placement=placement, ndim=self.ndim)
263237

@@ -1649,7 +1623,7 @@ class ExtensionBlock(libinternals.Block, EABackedBlock):
16491623
Notes
16501624
-----
16511625
This holds all 3rd-party extension array types. It's also the immediate
1652-
parent class for our internal extension types' blocks, CategoricalBlock.
1626+
parent class for our internal extension types' blocks.
16531627
16541628
ExtensionArrays are limited to 1-D.
16551629
"""
@@ -2066,17 +2040,6 @@ def convert(
20662040
return [self.make_block(res_values)]
20672041

20682042

2069-
class CategoricalBlock(ExtensionBlock):
2070-
# this Block type is kept for backwards-compatibility
2071-
__slots__ = ()
2072-
2073-
# GH#43232, GH#43334 self.values.dtype can be changed inplace until 2.0,
2074-
# so this cannot be cached
2075-
@property
2076-
def dtype(self) -> DtypeObj:
2077-
return self.values.dtype
2078-
2079-
20802043
# -----------------------------------------------------------------
20812044
# Constructor Helpers
20822045

@@ -2132,8 +2095,6 @@ def get_block_type(dtype: DtypeObj):
21322095
if isinstance(dtype, SparseDtype):
21332096
# Need this first(ish) so that Sparse[datetime] is sparse
21342097
cls = ExtensionBlock
2135-
elif isinstance(dtype, CategoricalDtype):
2136-
cls = CategoricalBlock
21372098
elif vtype is Timestamp:
21382099
cls = DatetimeTZBlock
21392100
elif isinstance(dtype, PeriodDtype):
@@ -2374,7 +2335,7 @@ def external_values(values: ArrayLike) -> ArrayLike:
23742335
elif isinstance(values, (DatetimeArray, TimedeltaArray)):
23752336
# NB: for datetime64tz this is different from np.asarray(values), since
23762337
# that returns an object-dtype ndarray of Timestamps.
2377-
# Avoid FutureWarning in .astype in casting from dt64tz to dt64
2338+
# Avoid raising in .astype in casting from dt64tz to dt64
23782339
return values._data
23792340
else:
23802341
return values

pandas/core/internals/managers.py

+3-31
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
)
7676
from pandas.core.internals.blocks import (
7777
Block,
78-
DatetimeTZBlock,
7978
NumpyBlock,
8079
ensure_block_shape,
8180
extend_blocks,
@@ -1021,27 +1020,9 @@ def __init__(
10211020
f"Number of Block dimensions ({block.ndim}) must equal "
10221021
f"number of axes ({self.ndim})"
10231022
)
1024-
if isinstance(block, DatetimeTZBlock) and block.values.ndim == 1:
1025-
# TODO(2.0): remove once fastparquet no longer needs this
1026-
warnings.warn(
1027-
"In a future version, the BlockManager constructor "
1028-
"will assume that a DatetimeTZBlock with block.ndim==2 "
1029-
"has block.values.ndim == 2.",
1030-
DeprecationWarning,
1031-
stacklevel=find_stack_level(),
1032-
)
1033-
1034-
# error: Incompatible types in assignment (expression has type
1035-
# "Union[ExtensionArray, ndarray]", variable has type
1036-
# "DatetimeArray")
1037-
block.values = ensure_block_shape( # type: ignore[assignment]
1038-
block.values, self.ndim
1039-
)
1040-
try:
1041-
block._cache.clear()
1042-
except AttributeError:
1043-
# _cache not initialized
1044-
pass
1023+
# As of 2.0, the caller is responsible for ensuring that
1024+
# DatetimeTZBlock with block.ndim == 2 has block.values.ndim ==2;
1025+
# previously there was a special check for fastparquet compat.
10451026

10461027
self._verify_integrity()
10471028

@@ -1898,20 +1879,11 @@ def __init__(
18981879
refs: list[weakref.ref | None] | None = None,
18991880
parent: object = None,
19001881
verify_integrity: bool = False,
1901-
fastpath=lib.no_default,
19021882
) -> None:
19031883
# Assertions disabled for performance
19041884
# assert isinstance(block, Block), type(block)
19051885
# assert isinstance(axis, Index), type(axis)
19061886

1907-
if fastpath is not lib.no_default:
1908-
warnings.warn(
1909-
"The `fastpath` keyword is deprecated and will be removed "
1910-
"in a future version.",
1911-
FutureWarning,
1912-
stacklevel=find_stack_level(),
1913-
)
1914-
19151887
self.axes = [axis]
19161888
self.blocks = (block,)
19171889
self.refs = refs

pandas/tests/internals/test_internals.py

-14
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,6 @@ def test_split(self):
356356
for res, exp in zip(result, expected):
357357
assert_block_equal(res, exp)
358358

359-
def test_is_categorical_deprecated(self, fblock):
360-
# GH#40571
361-
blk = fblock
362-
with tm.assert_produces_warning(DeprecationWarning):
363-
blk.is_categorical
364-
365359

366360
class TestBlockManager:
367361
def test_attrs(self):
@@ -1432,11 +1426,3 @@ def test_make_block_no_pandas_array(block_maker):
14321426
)
14331427
assert result.dtype.kind in ["i", "u"]
14341428
assert result.is_extension is False
1435-
1436-
1437-
def test_single_block_manager_fastpath_deprecated():
1438-
# GH#33092
1439-
ser = Series(range(3))
1440-
blk = ser._data.blocks[0]
1441-
with tm.assert_produces_warning(FutureWarning):
1442-
SingleBlockManager(blk, ser.index, fastpath=True)

pandas/tests/io/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
pytest.mark.filterwarnings(
66
"ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning"
77
),
8-
pytest.mark.filterwarnings(
9-
"ignore:Block.is_categorical is deprecated:DeprecationWarning"
10-
),
118
pytest.mark.filterwarnings(
129
r"ignore:`np\.bool` is a deprecated alias:DeprecationWarning"
1310
),

pandas/tests/io/test_common.py

-3
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ def test_read_expands_user_home_dir(
317317
),
318318
],
319319
)
320-
@pytest.mark.filterwarnings(
321-
"ignore:CategoricalBlock is deprecated:DeprecationWarning"
322-
)
323320
@pytest.mark.filterwarnings( # pytables np.object usage
324321
"ignore:`np.object` is a deprecated alias:DeprecationWarning"
325322
)

pandas/tests/io/test_feather.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
@filter_sparse
1717
@pytest.mark.single_cpu
18-
@pytest.mark.filterwarnings("ignore:CategoricalBlock is deprecated:DeprecationWarning")
1918
class TestFeather:
2019
def check_error_on_write(self, df, exc, err_msg):
2120
# check that we are raising the exception

pandas/tests/io/test_orc.py

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
pytest.importorskip("pyarrow.orc")
1616

17-
pytestmark = pytest.mark.filterwarnings(
18-
"ignore:RangeIndex.* is deprecated:DeprecationWarning"
19-
)
20-
2117

2218
@pytest.fixture
2319
def dirpath(datapath):

pandas/tests/io/test_parquet.py

-6
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@
5353
_HAVE_FASTPARQUET = False
5454

5555

56-
pytestmark = pytest.mark.filterwarnings(
57-
"ignore:RangeIndex.* is deprecated:DeprecationWarning"
58-
)
59-
60-
6156
# TODO(ArrayManager) fastparquet relies on BlockManager internals
6257

6358
# setup engines & skips
@@ -688,7 +683,6 @@ def test_read_empty_array(self, pa, dtype):
688683
)
689684

690685

691-
@pytest.mark.filterwarnings("ignore:CategoricalBlock is deprecated:DeprecationWarning")
692686
class TestParquetPyArrow(Base):
693687
def test_basic(self, pa, df_full):
694688

pandas/tests/test_downstream.py

-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def test_geopandas():
234234

235235
# Cython import warning
236236
@pytest.mark.filterwarnings("ignore:can't resolve:ImportWarning")
237-
@pytest.mark.filterwarnings("ignore:RangeIndex.* is deprecated:DeprecationWarning")
238237
def test_pyarrow(df):
239238

240239
pyarrow = import_module("pyarrow")

0 commit comments

Comments
 (0)