Skip to content

Commit 0dcef9b

Browse files
authored
CLN: share to_native_types (#36965)
1 parent f47a93c commit 0dcef9b

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

pandas/core/internals/blocks.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ def _can_hold_element(self, element: Any) -> bool:
20852085
return is_integer(element) or (is_float(element) and element.is_integer())
20862086

20872087

2088-
class DatetimeLikeBlockMixin:
2088+
class DatetimeLikeBlockMixin(Block):
20892089
"""Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock."""
20902090

20912091
@property
@@ -2123,8 +2123,15 @@ def shift(self, periods, axis=0, fill_value=None):
21232123
new_values = values.shift(periods, fill_value=fill_value, axis=axis)
21242124
return self.make_block_same_class(new_values)
21252125

2126+
def to_native_types(self, na_rep="NaT", **kwargs):
2127+
""" convert to our native types format """
2128+
arr = self.array_values()
2129+
2130+
result = arr._format_native_types(na_rep=na_rep, **kwargs)
2131+
return self.make_block(result)
21262132

2127-
class DatetimeBlock(DatetimeLikeBlockMixin, Block):
2133+
2134+
class DatetimeBlock(DatetimeLikeBlockMixin):
21282135
__slots__ = ()
21292136
is_datetime = True
21302137

@@ -2204,15 +2211,6 @@ def _can_hold_element(self, element: Any) -> bool:
22042211

22052212
return is_valid_nat_for_dtype(element, self.dtype)
22062213

2207-
def to_native_types(self, na_rep="NaT", date_format=None, **kwargs):
2208-
""" convert to our native types format """
2209-
dta = self.array_values()
2210-
2211-
result = dta._format_native_types(
2212-
na_rep=na_rep, date_format=date_format, **kwargs
2213-
)
2214-
return self.make_block(result)
2215-
22162214
def set(self, locs, values):
22172215
"""
22182216
See Block.set.__doc__
@@ -2412,12 +2410,6 @@ def fillna(self, value, **kwargs):
24122410
)
24132411
return super().fillna(value, **kwargs)
24142412

2415-
def to_native_types(self, na_rep="NaT", **kwargs):
2416-
""" convert to our native types format """
2417-
tda = self.array_values()
2418-
res = tda._format_native_types(na_rep, **kwargs)
2419-
return self.make_block(res)
2420-
24212413

24222414
class BoolBlock(NumericBlock):
24232415
__slots__ = ()

0 commit comments

Comments
 (0)