From 9706c06df0920ef2616a65d8edb9e6bb381fea39 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 7 Oct 2020 18:15:45 -0700 Subject: [PATCH 1/2] CLN: share to_native_types --- pandas/core/internals/blocks.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 09f276be7d64a..de69a8fb3d58c 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2108,6 +2108,13 @@ def shift(self, periods, axis=0, fill_value=None): new_values = values.shift(periods, fill_value=fill_value, axis=axis) return self.make_block_same_class(new_values) + def to_native_types(self, na_rep="NaT", **kwargs): + """ convert to our native types format """ + arr = self.array_values() + + result = arr._format_native_types(na_rep=na_rep, **kwargs) + return self.make_block(result) + class DatetimeBlock(DatetimeLikeBlockMixin, Block): __slots__ = () @@ -2187,15 +2194,6 @@ def _can_hold_element(self, element: Any) -> bool: return is_valid_nat_for_dtype(element, self.dtype) - def to_native_types(self, na_rep="NaT", date_format=None, **kwargs): - """ convert to our native types format """ - dta = self.array_values() - - result = dta._format_native_types( - na_rep=na_rep, date_format=date_format, **kwargs - ) - return self.make_block(result) - def set(self, locs, values): """ See Block.set.__doc__ @@ -2407,12 +2405,6 @@ def fillna(self, value, **kwargs): ) return super().fillna(value, **kwargs) - def to_native_types(self, na_rep="NaT", **kwargs): - """ convert to our native types format """ - tda = self.array_values() - res = tda._format_native_types(na_rep, **kwargs) - return self.make_block(res) - class BoolBlock(NumericBlock): __slots__ = () From 0f7e49a5b2bf20d2e35dcb4d1c285bb5f36f8a4c Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 7 Oct 2020 18:59:42 -0700 Subject: [PATCH 2/2] mypy fixup --- pandas/core/internals/blocks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index de69a8fb3d58c..7332d01f15993 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2070,7 +2070,7 @@ def _can_hold_element(self, element: Any) -> bool: return is_integer(element) or (is_float(element) and element.is_integer()) -class DatetimeLikeBlockMixin: +class DatetimeLikeBlockMixin(Block): """Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock.""" @property @@ -2116,7 +2116,7 @@ def to_native_types(self, na_rep="NaT", **kwargs): return self.make_block(result) -class DatetimeBlock(DatetimeLikeBlockMixin, Block): +class DatetimeBlock(DatetimeLikeBlockMixin): __slots__ = () is_datetime = True