From 734fd137105210885492b73ad8d5de4fdf054891 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Tue, 10 May 2022 18:27:10 -0700 Subject: [PATCH 1/2] CLN: DatetimeTZBlock don't override values_for_json --- pandas/core/internals/blocks.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index c8430a9266ea5..29f3f884566d0 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1986,12 +1986,10 @@ class DatetimeTZBlock(DatetimeLikeBlock): is_extension = True _validate_ndim = True _can_consolidate = False - - def values_for_json(self) -> np.ndarray: - # force dt64tz to go through object dtype - # tz info will be lost when converting to - # dt64 which is naive - return self.values.astype(object) + + # Don't use values_for_json from DatetimeLikeBlock since it is + # an invalid optimization here(drop the tz) + values_for_json = NDArrayBackedExtensionBlock.values_for_json class ObjectBlock(NumpyBlock): From 4dca662d437163ec5ec7c403f2ff8a6ba380e50f Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Tue, 10 May 2022 18:27:50 -0700 Subject: [PATCH 2/2] Update blocks.py --- pandas/core/internals/blocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 29f3f884566d0..82daaa2843091 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1986,7 +1986,7 @@ class DatetimeTZBlock(DatetimeLikeBlock): is_extension = True _validate_ndim = True _can_consolidate = False - + # Don't use values_for_json from DatetimeLikeBlock since it is # an invalid optimization here(drop the tz) values_for_json = NDArrayBackedExtensionBlock.values_for_json