Skip to content

Commit

Permalink
Merge pull request pandas-dev#4 from ofsouzap/my-typing-fixes
Browse files Browse the repository at this point in the history
`nanops.nanmedian` typing fix
  • Loading branch information
dl-lim authored Nov 9, 2024
2 parents 160d290 + f6b30d3 commit 021cc5a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def nanmean(


@bottleneck_switch()
def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=None):
def nanmedian(values: np.ndarray, *, axis: AxisInt | None = None, skipna: bool = True, mask=None) -> float | np.ndarray:
"""
Parameters
----------
Expand All @@ -738,7 +738,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
Returns
-------
result : float
result : float | ndarray
Unless input is a float array, in which case use the same
precision as the input array.
Expand All @@ -758,7 +758,7 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
# cases we never need to set NaN to the masked values
using_nan_sentinel = values.dtype.kind == "f" and mask is None

def get_median(x, _mask=None):
def get_median(x: np.ndarray, _mask=None):
if _mask is None:
_mask = notna(x)
else:
Expand Down Expand Up @@ -794,6 +794,8 @@ def get_median(x, _mask=None):

notempty = values.size

res: float | np.ndarray

# an array from a frame
if values.ndim > 1 and axis is not None:
# there's a non-empty array to apply over otherwise numpy raises
Expand Down

0 comments on commit 021cc5a

Please sign in to comment.