From 24ae673c0c7af96e3d6824ce82236511387fbbca Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 26 Oct 2021 09:03:34 -0700 Subject: [PATCH 1/2] DEPR: warn on checks retained for fastparquet --- pandas/core/internals/blocks.py | 16 ++++++++++++++-- pandas/core/internals/managers.py | 11 ++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index de612b367f78f..33fd9ca9af331 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -31,6 +31,7 @@ npt, ) from pandas.util._decorators import cache_readonly +from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_bool_kwarg from pandas.core.dtypes.cast import ( @@ -268,8 +269,19 @@ def make_block_same_class( placement = self._mgr_locs if values.dtype.kind in ["m", "M"]: - # TODO: remove this once fastparquet has stopped relying on it - values = ensure_wrapped_if_datetimelike(values) + + new_values = ensure_wrapped_if_datetimelike(values) + if new_values is not values: + # TODO(2.0): remove once fastparquet has stopped relying on it + warnings.warn( + DeprecationWarning, + "In a future version, Block.make_block_same_class will " + "assume that datetime64 and timedelta64 ndarrays have " + "already been cast to DatetimeArray and TimedeltaArray, " + "respectively.", + stacklevel=find_stack_level(), + ) + values = new_values # We assume maybe_coerce_values has already been called return type(self)(values, placement=placement, ndim=self.ndim) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 9b29216fa407b..c20c0b6b25f85 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -27,6 +27,7 @@ ) from pandas.errors import PerformanceWarning from pandas.util._decorators import cache_readonly +from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_bool_kwarg from pandas.core.dtypes.cast import infer_dtype_from_scalar @@ -910,7 +911,15 @@ def __init__( f"number of axes ({self.ndim})" ) if isinstance(block, DatetimeTZBlock) and block.values.ndim == 1: - # TODO: remove once fastparquet no longer needs this + # TODO(2.0): remove once fastparquet no longer needs this + warnings.warn( + DeprecationWarning, + "In a future version, the BlockManager constructor " + "will assume that a DatetimeTZBlock with block.ndim==2 " + "has block.values.ndim == 2.", + stacklevel=find_stack_level(), + ) + # error: Incompatible types in assignment (expression has type # "Union[ExtensionArray, ndarray]", variable has type # "DatetimeArray") From b4dfe48e69d86fdd520202cfc3764b5be4736dda Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 30 Oct 2021 08:16:43 -0700 Subject: [PATCH 2/2] arg order fixup --- pandas/core/internals/blocks.py | 2 +- pandas/core/internals/managers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 679e32bb5d79d..a0f116c1f8f88 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -274,11 +274,11 @@ def make_block_same_class( if new_values is not values: # TODO(2.0): remove once fastparquet has stopped relying on it warnings.warn( - DeprecationWarning, "In a future version, Block.make_block_same_class will " "assume that datetime64 and timedelta64 ndarrays have " "already been cast to DatetimeArray and TimedeltaArray, " "respectively.", + DeprecationWarning, stacklevel=find_stack_level(), ) values = new_values diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index c1c3bc6479c06..745cddee93479 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -910,10 +910,10 @@ def __init__( if isinstance(block, DatetimeTZBlock) and block.values.ndim == 1: # TODO(2.0): remove once fastparquet no longer needs this warnings.warn( - DeprecationWarning, "In a future version, the BlockManager constructor " "will assume that a DatetimeTZBlock with block.ndim==2 " "has block.values.ndim == 2.", + DeprecationWarning, stacklevel=find_stack_level(), )