11
11
)
12
12
from typing import (
13
13
TYPE_CHECKING ,
14
+ Any ,
14
15
Callable ,
15
16
Sequence ,
16
17
cast ,
@@ -50,7 +51,7 @@ def describe_ndframe(
50
51
include : str | Sequence [str ] | None ,
51
52
exclude : str | Sequence [str ] | None ,
52
53
datetime_is_numeric : bool ,
53
- percentiles : Sequence [float ] | None ,
54
+ percentiles : Sequence [float ] | np . ndarray | None ,
54
55
) -> FrameOrSeries :
55
56
"""Describe series or dataframe.
56
57
@@ -111,7 +112,7 @@ def __init__(self, obj: DataFrame | Series, datetime_is_numeric: bool):
111
112
self .datetime_is_numeric = datetime_is_numeric
112
113
113
114
@abstractmethod
114
- def describe (self , percentiles : Sequence [float ]) -> DataFrame | Series :
115
+ def describe (self , percentiles : Sequence [float ] | np . ndarray ) -> DataFrame | Series :
115
116
"""Do describe either series or dataframe.
116
117
117
118
Parameters
@@ -126,7 +127,7 @@ class SeriesDescriber(NDFrameDescriberAbstract):
126
127
127
128
obj : Series
128
129
129
- def describe (self , percentiles : Sequence [float ]) -> Series :
130
+ def describe (self , percentiles : Sequence [float ] | np . ndarray ) -> Series :
130
131
describe_func = select_describe_func (
131
132
self .obj ,
132
133
self .datetime_is_numeric ,
@@ -165,7 +166,7 @@ def __init__(
165
166
166
167
super ().__init__ (obj , datetime_is_numeric = datetime_is_numeric )
167
168
168
- def describe (self , percentiles : Sequence [float ]) -> DataFrame :
169
+ def describe (self , percentiles : Sequence [float ] | np . ndarray ) -> DataFrame :
169
170
data = self ._select_data ()
170
171
171
172
ldesc : list [Series ] = []
@@ -387,18 +388,19 @@ def select_describe_func(
387
388
return describe_categorical_1d
388
389
389
390
390
- def refine_percentiles (percentiles : Sequence [float ] | None ) -> Sequence [float ]:
391
- """Ensure that percentiles are unique and sorted.
391
+ def refine_percentiles (
392
+ percentiles : Sequence [float ] | np .ndarray | None ,
393
+ ) -> np .ndarray [Any , np .dtype [np .float64 ]]:
394
+ """
395
+ Ensure that percentiles are unique and sorted.
392
396
393
397
Parameters
394
398
----------
395
399
percentiles : list-like of numbers, optional
396
400
The percentiles to include in the output.
397
401
"""
398
402
if percentiles is None :
399
- # error: Incompatible return value type (got "ndarray", expected
400
- # "Sequence[float]")
401
- return np .array ([0.25 , 0.5 , 0.75 ]) # type: ignore[return-value]
403
+ return np .array ([0.25 , 0.5 , 0.75 ])
402
404
403
405
# explicit conversion of `percentiles` to list
404
406
percentiles = list (percentiles )
@@ -410,9 +412,7 @@ def refine_percentiles(percentiles: Sequence[float] | None) -> Sequence[float]:
410
412
if 0.5 not in percentiles :
411
413
percentiles .append (0.5 )
412
414
413
- # error: Incompatible types in assignment (expression has type "ndarray", variable
414
- # has type "Optional[Sequence[float]]")
415
- percentiles = np .asarray (percentiles ) # type: ignore[assignment]
415
+ percentiles = np .asarray (percentiles )
416
416
417
417
# sort and check for duplicates
418
418
unique_pcts = np .unique (percentiles )
0 commit comments