7
7
import numpy as np
8
8
9
9
from pandas ._libs import algos , lib
10
+ from pandas ._typing import DtypeObj
10
11
from pandas .compat ._optional import import_optional_dependency
11
12
12
13
from pandas .core .dtypes .cast import infer_dtype_from_array
13
14
from pandas .core .dtypes .common import (
14
15
ensure_float64 ,
15
- is_datetime64_dtype ,
16
- is_datetime64tz_dtype ,
17
16
is_integer_dtype ,
18
17
is_numeric_v_string_like ,
19
18
is_scalar ,
20
- is_timedelta64_dtype ,
21
19
needs_i8_conversion ,
22
20
)
23
21
from pandas .core .dtypes .missing import isna
@@ -72,7 +70,7 @@ def mask_missing(arr, values_to_mask):
72
70
return mask
73
71
74
72
75
- def clean_fill_method (method , allow_nearest = False ):
73
+ def clean_fill_method (method , allow_nearest : bool = False ):
76
74
# asfreq is compat for resampling
77
75
if method in [None , "asfreq" ]:
78
76
return None
@@ -543,7 +541,12 @@ def _cubicspline_interpolate(xi, yi, x, axis=0, bc_type="not-a-knot", extrapolat
543
541
544
542
545
543
def interpolate_2d (
546
- values , method = "pad" , axis = 0 , limit = None , fill_value = None , dtype = None
544
+ values ,
545
+ method = "pad" ,
546
+ axis = 0 ,
547
+ limit = None ,
548
+ fill_value = None ,
549
+ dtype : Optional [DtypeObj ] = None ,
547
550
):
548
551
"""
549
552
Perform an actual interpolation of values, values will be make 2-d if
@@ -584,18 +587,14 @@ def interpolate_2d(
584
587
return values
585
588
586
589
587
- def _cast_values_for_fillna (values , dtype ):
590
+ def _cast_values_for_fillna (values , dtype : DtypeObj ):
588
591
"""
589
592
Cast values to a dtype that algos.pad and algos.backfill can handle.
590
593
"""
591
594
# TODO: for int-dtypes we make a copy, but for everything else this
592
595
# alters the values in-place. Is this intentional?
593
596
594
- if (
595
- is_datetime64_dtype (dtype )
596
- or is_datetime64tz_dtype (dtype )
597
- or is_timedelta64_dtype (dtype )
598
- ):
597
+ if needs_i8_conversion (dtype ):
599
598
values = values .view (np .int64 )
600
599
601
600
elif is_integer_dtype (values ):
@@ -605,7 +604,7 @@ def _cast_values_for_fillna(values, dtype):
605
604
return values
606
605
607
606
608
- def _fillna_prep (values , mask = None , dtype = None ):
607
+ def _fillna_prep (values , mask = None , dtype : Optional [ DtypeObj ] = None ):
609
608
# boilerplate for pad_1d, backfill_1d, pad_2d, backfill_2d
610
609
if dtype is None :
611
610
dtype = values .dtype
@@ -620,19 +619,19 @@ def _fillna_prep(values, mask=None, dtype=None):
620
619
return values , mask
621
620
622
621
623
- def pad_1d (values , limit = None , mask = None , dtype = None ):
622
+ def pad_1d (values , limit = None , mask = None , dtype : Optional [ DtypeObj ] = None ):
624
623
values , mask = _fillna_prep (values , mask , dtype )
625
624
algos .pad_inplace (values , mask , limit = limit )
626
625
return values
627
626
628
627
629
- def backfill_1d (values , limit = None , mask = None , dtype = None ):
628
+ def backfill_1d (values , limit = None , mask = None , dtype : Optional [ DtypeObj ] = None ):
630
629
values , mask = _fillna_prep (values , mask , dtype )
631
630
algos .backfill_inplace (values , mask , limit = limit )
632
631
return values
633
632
634
633
635
- def pad_2d (values , limit = None , mask = None , dtype = None ):
634
+ def pad_2d (values , limit = None , mask = None , dtype : Optional [ DtypeObj ] = None ):
636
635
values , mask = _fillna_prep (values , mask , dtype )
637
636
638
637
if np .all (values .shape ):
@@ -643,7 +642,7 @@ def pad_2d(values, limit=None, mask=None, dtype=None):
643
642
return values
644
643
645
644
646
- def backfill_2d (values , limit = None , mask = None , dtype = None ):
645
+ def backfill_2d (values , limit = None , mask = None , dtype : Optional [ DtypeObj ] = None ):
647
646
values , mask = _fillna_prep (values , mask , dtype )
648
647
649
648
if np .all (values .shape ):
0 commit comments