Skip to content

CLN: share to_native_types #36965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2108,8 +2108,15 @@ 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):

class DatetimeBlock(DatetimeLikeBlockMixin):
__slots__ = ()
is_datetime = True

Expand Down Expand Up @@ -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__
Expand Down Expand Up @@ -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__ = ()
Expand Down