1
1
from datetime import datetime , timedelta
2
2
import inspect
3
3
import re
4
- from typing import Any , List
4
+ from typing import TYPE_CHECKING , Any , List , Optional
5
5
import warnings
6
6
7
7
import numpy as np
83
83
import pandas .core .missing as missing
84
84
from pandas .core .nanops import nanpercentile
85
85
86
+ if TYPE_CHECKING :
87
+ from pandas import Index
88
+
86
89
87
90
class Block (PandasObject ):
88
91
"""
@@ -1066,16 +1069,16 @@ def coerce_to_target_dtype(self, other):
1066
1069
1067
1070
def interpolate (
1068
1071
self ,
1069
- method = "pad" ,
1070
- axis = 0 ,
1071
- index = None ,
1072
- inplace = False ,
1073
- limit = None ,
1074
- limit_direction = "forward" ,
1075
- limit_area = None ,
1076
- fill_value = None ,
1077
- coerce = False ,
1078
- downcast = None ,
1072
+ method : str = "pad" ,
1073
+ axis : int = 0 ,
1074
+ index : Optional [ "Index" ] = None ,
1075
+ inplace : bool = False ,
1076
+ limit : Optional [ int ] = None ,
1077
+ limit_direction : str = "forward" ,
1078
+ limit_area : Optional [ str ] = None ,
1079
+ fill_value : Optional [ Any ] = None ,
1080
+ coerce : bool = False ,
1081
+ downcast : Optional [ str ] = None ,
1079
1082
** kwargs ,
1080
1083
):
1081
1084
@@ -1115,6 +1118,9 @@ def check_int_bool(self, inplace):
1115
1118
r = check_int_bool (self , inplace )
1116
1119
if r is not None :
1117
1120
return r
1121
+
1122
+ assert index is not None # for mypy
1123
+
1118
1124
return self ._interpolate (
1119
1125
method = m ,
1120
1126
index = index ,
@@ -1130,13 +1136,13 @@ def check_int_bool(self, inplace):
1130
1136
1131
1137
def _interpolate_with_fill (
1132
1138
self ,
1133
- method = "pad" ,
1134
- axis = 0 ,
1135
- inplace = False ,
1136
- limit = None ,
1137
- fill_value = None ,
1138
- coerce = False ,
1139
- downcast = None ,
1139
+ method : str = "pad" ,
1140
+ axis : int = 0 ,
1141
+ inplace : bool = False ,
1142
+ limit : Optional [ int ] = None ,
1143
+ fill_value : Optional [ Any ] = None ,
1144
+ coerce : bool = False ,
1145
+ downcast : Optional [ str ] = None ,
1140
1146
) -> List ["Block" ]:
1141
1147
""" fillna but using the interpolate machinery """
1142
1148
inplace = validate_bool_kwarg (inplace , "inplace" )
@@ -1169,15 +1175,15 @@ def _interpolate_with_fill(
1169
1175
1170
1176
def _interpolate (
1171
1177
self ,
1172
- method = None ,
1173
- index = None ,
1174
- fill_value = None ,
1175
- axis = 0 ,
1176
- limit = None ,
1177
- limit_direction = "forward" ,
1178
- limit_area = None ,
1179
- inplace = False ,
1180
- downcast = None ,
1178
+ method : str ,
1179
+ index : "Index" ,
1180
+ fill_value : Optional [ Any ] = None ,
1181
+ axis : int = 0 ,
1182
+ limit : Optional [ int ] = None ,
1183
+ limit_direction : str = "forward" ,
1184
+ limit_area : Optional [ str ] = None ,
1185
+ inplace : bool = False ,
1186
+ downcast : Optional [ str ] = None ,
1181
1187
** kwargs ,
1182
1188
) -> List ["Block" ]:
1183
1189
""" interpolate using scipy wrappers """
@@ -1200,14 +1206,14 @@ def _interpolate(
1200
1206
)
1201
1207
# process 1-d slices in the axis direction
1202
1208
1203
- def func (x ) :
1209
+ def func (yvalues : np . ndarray ) -> np . ndarray :
1204
1210
1205
1211
# process a 1-d slice, returning it
1206
1212
# should the axis argument be handled below in apply_along_axis?
1207
1213
# i.e. not an arg to missing.interpolate_1d
1208
1214
return missing .interpolate_1d (
1209
- index ,
1210
- x ,
1215
+ xvalues = index ,
1216
+ yvalues = yvalues ,
1211
1217
method = method ,
1212
1218
limit = limit ,
1213
1219
limit_direction = limit_direction ,
0 commit comments