|
10 | 10 | from pandas.compat import range
|
11 | 11 |
|
12 | 12 |
|
| 13 | +def mask_missing(arr, values_to_mask): |
| 14 | + """ |
| 15 | + Return a masking array of same size/shape as arr |
| 16 | + with entries equaling any member of values_to_mask set to True |
| 17 | + """ |
| 18 | + if not isinstance(values_to_mask, (list, np.ndarray)): |
| 19 | + values_to_mask = [values_to_mask] |
| 20 | + |
| 21 | + try: |
| 22 | + values_to_mask = np.array(values_to_mask, dtype=arr.dtype) |
| 23 | + except Exception: |
| 24 | + values_to_mask = np.array(values_to_mask, dtype=object) |
| 25 | + |
| 26 | + na_mask = com.isnull(values_to_mask) |
| 27 | + nonna = values_to_mask[~na_mask] |
| 28 | + |
| 29 | + mask = None |
| 30 | + for x in nonna: |
| 31 | + if mask is None: |
| 32 | + |
| 33 | + # numpy elementwise comparison warning |
| 34 | + if com.is_numeric_v_string_like(arr, x): |
| 35 | + mask = False |
| 36 | + else: |
| 37 | + mask = arr == x |
| 38 | + |
| 39 | + # if x is a string and arr is not, then we get False and we must |
| 40 | + # expand the mask to size arr.shape |
| 41 | + if lib.isscalar(mask): |
| 42 | + mask = np.zeros(arr.shape, dtype=bool) |
| 43 | + else: |
| 44 | + |
| 45 | + # numpy elementwise comparison warning |
| 46 | + if com.is_numeric_v_string_like(arr, x): |
| 47 | + mask |= False |
| 48 | + else: |
| 49 | + mask |= arr == x |
| 50 | + |
| 51 | + if na_mask.any(): |
| 52 | + if mask is None: |
| 53 | + mask = com.isnull(arr) |
| 54 | + else: |
| 55 | + mask |= com.isnull(arr) |
| 56 | + |
| 57 | + return mask |
| 58 | + |
| 59 | + |
13 | 60 | def clean_fill_method(method, allow_nearest=False):
|
14 | 61 | if method is None:
|
15 | 62 | return None
|
@@ -239,7 +286,7 @@ def interpolate_2d(values, method='pad', axis=0, limit=None, fill_value=None,
|
239 | 286 | if fill_value is None:
|
240 | 287 | mask = None
|
241 | 288 | else: # todo create faster fill func without masking
|
242 |
| - mask = com.mask_missing(transf(values), fill_value) |
| 289 | + mask = mask_missing(transf(values), fill_value) |
243 | 290 |
|
244 | 291 | method = clean_fill_method(method)
|
245 | 292 | if method == 'pad':
|
|
0 commit comments