Skip to content

Commit e8989e6

Browse files
committed
ENH: support of pandas.DataFrame.hist for datetime data
1 parent a09259b commit e8989e6

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -5438,6 +5438,9 @@ def _get_numeric_data(self):
54385438
def _get_bool_data(self):
54395439
return self._constructor(self._mgr.get_bool_data()).__finalize__(self)
54405440

5441+
def _get_numeric_or_datetime_data(self):
5442+
return self._constructor(self._mgr.get_numeric_or_datetime_data()).__finalize__(self)
5443+
54415444
# ----------------------------------------------------------------------
54425445
# Internal Interface Methods
54435446

pandas/core/internals/managers.py

+9
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,15 @@ def get_numeric_data(self, copy: bool = False) -> "BlockManager":
693693
"""
694694
return self._combine([b for b in self.blocks if b.is_numeric], copy)
695695

696+
def get_numeric_or_datetime_data(self, copy: bool = False) -> "BlockManager":
697+
"""
698+
Parameters
699+
----------
700+
copy : bool, default False
701+
Whether to copy the blocks
702+
"""
703+
return self._combine([b for b in self.blocks if b.is_numeric or b.is_datetime], copy)
704+
696705
def _combine(self: T, blocks: List[Block], copy: bool = True) -> T:
697706
""" return a new manager with the blocks """
698707
if len(blocks) == 0:

pandas/plotting/_matplotlib/hist.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ def hist_frame(
417417
if not isinstance(column, (list, np.ndarray, ABCIndexClass)):
418418
column = [column]
419419
data = data[column]
420-
data = data._get_numeric_data()
420+
# GH32590
421+
data = data._get_numeric_or_datetime_data()
421422
naxes = len(data.columns)
422423

423424
if naxes == 0:

0 commit comments

Comments
 (0)