Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,16 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps):
"""

_typ = "datetimearray"
_internal_fill_value = np.datetime64("NaT", "ns")
_recognized_scalars = (datetime, np.datetime64)
_is_recognized_dtype: Callable[[DtypeObj], bool] = lambda x: lib.is_np_dtype(
x, "M"
) or isinstance(x, DatetimeTZDtype)
_infer_matches = ("datetime", "datetime64", "date")

@property
def _internal_fill_value(self) -> np.datetime64:
return np.datetime64("NaT", self.unit)

@property
def _scalar_type(self) -> type[Timestamp]:
return Timestamp
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ class TimedeltaArray(dtl.TimelikeOps):
"""

_typ = "timedeltaarray"
_internal_fill_value = np.timedelta64("NaT", "ns")
_recognized_scalars = (timedelta, np.timedelta64, Tick)
_is_recognized_dtype: Callable[[DtypeObj], bool] = lambda x: lib.is_np_dtype(x, "m")
_infer_matches = ("timedelta", "timedelta64")

@property
def _internal_fill_value(self) -> np.timedelta64:
return np.timedelta64("NaT", self.unit)

@property
def _scalar_type(self) -> type[Timedelta]:
return Timedelta
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/series/methods/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,10 @@ def test_quantile_dtype_size(self, any_int_ea_dtype):
result = ser.quantile([0.1, 0.5])
expected = Series([1, 1], dtype=any_int_ea_dtype, index=[0.1, 0.5])
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("typ", ["datetime64", "timedelta64"])
def test_quantile_empty_datetimelike(typ, unit):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to also add a dataframe version of this test, such that there is an actual dtype to verify (to assert it has preserved the unit)

ser = Series([], dtype=f"{typ}[{unit}]")
result = ser.quantile()
assert result is pd.NaT
Loading