|
42 | 42 | from numba import (types, numpy_support, cgutils) |
43 | 43 | from numba.typed import Dict |
44 | 44 | from numba import prange |
| 45 | +from numba.targets.arraymath import get_isnan |
45 | 46 |
|
46 | 47 | import sdc |
47 | 48 | import sdc.datatypes.common_functions as common_functions |
@@ -5019,61 +5020,40 @@ def hpat_pandas_series_fillna(self, value=None, method=None, axis=None, inplace= |
5019 | 5020 | raise TypingError('{} Not implemented when Series dtype is {} and\ |
5020 | 5021 | inplace={}'.format(_func_name, self.dtype, inplace)) |
5021 | 5022 |
|
5022 | | - elif isinstance(self.dtype, (types.Integer, types.Boolean)): |
5023 | | - def hpat_pandas_series_no_nan_fillna_impl(self, value=None, method=None, axis=None, inplace=False, |
5024 | | - limit=None, downcast=None): |
5025 | | - # no NaNs in series of Integers or Booleans |
5026 | | - return None |
5027 | | - |
5028 | | - return hpat_pandas_series_no_nan_fillna_impl |
5029 | 5023 | else: |
5030 | 5024 | def hpat_pandas_series_fillna_impl(self, value=None, method=None, axis=None, inplace=False, |
5031 | 5025 | limit=None, downcast=None): |
5032 | | - na_data_arr = sdc.hiframes.api.get_nan_mask(self._data) |
5033 | | - self._data[na_data_arr] = value |
5034 | | - return None |
| 5026 | + return numpy_like.fillna(self._data, inplace=inplace, value=value) |
5035 | 5027 |
|
5036 | 5028 | return hpat_pandas_series_fillna_impl |
| 5029 | + |
5037 | 5030 | else: |
5038 | 5031 | # non inplace implementations, copy array, fill the NA/NaN and return a new Series |
5039 | 5032 | if isinstance(self.dtype, types.UnicodeType): |
5040 | 5033 | # For StringArrayType implementation is taken from _series_fillna_str_alloc_impl |
5041 | 5034 | # (can be called directly when it's index handling is fixed) |
5042 | 5035 | def hpat_pandas_series_str_fillna_impl(self, value=None, method=None, axis=None, |
5043 | 5036 | inplace=False, limit=None, downcast=None): |
5044 | | - |
5045 | | - n = len(self._data) |
5046 | | - num_chars = 0 |
5047 | | - # get total chars in new array |
5048 | | - for i in prange(n): |
5049 | | - s = self._data[i] |
5050 | | - if sdc.hiframes.api.isna(self._data, i): |
5051 | | - num_chars += len(value) |
5052 | | - else: |
5053 | | - num_chars += len(s) |
5054 | | - |
5055 | | - filled_data = pre_alloc_string_array(n, num_chars) |
5056 | | - for i in prange(n): |
5057 | | - if sdc.hiframes.api.isna(self._data, i): |
5058 | | - filled_data[i] = value |
5059 | | - else: |
5060 | | - filled_data[i] = self._data[i] |
5061 | | - return pandas.Series(data=filled_data, index=self._index, name=self._name) |
| 5037 | + return pandas.Series(data=numpy_like.fillna(self._data, inplace=inplace, value=value), |
| 5038 | + index=self._index, |
| 5039 | + name=self._name) |
5062 | 5040 |
|
5063 | 5041 | return hpat_pandas_series_str_fillna_impl |
5064 | 5042 |
|
5065 | 5043 | elif isinstance(self.dtype, (types.Integer, types.Boolean)): |
5066 | 5044 | def hpat_pandas_series_no_nan_fillna_impl(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None): |
5067 | | - return pandas.Series(data=numpy.copy(self._data), index=self._index, name=self._name) |
| 5045 | + return pandas.Series(data=numpy_like.fillna(self._data, inplace=inplace, value=value), |
| 5046 | + index=self._index, |
| 5047 | + name=self._name) |
5068 | 5048 |
|
5069 | 5049 | return hpat_pandas_series_no_nan_fillna_impl |
5070 | 5050 |
|
5071 | 5051 | else: |
5072 | 5052 | def hpat_pandas_series_fillna_impl(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None): |
5073 | | - na_data_arr = sdc.hiframes.api.get_nan_mask(self._data) |
5074 | | - filled_data = numpy.copy(self._data) |
5075 | | - filled_data[na_data_arr] = value |
5076 | | - return pandas.Series(data=filled_data, index=self._index, name=self._name) |
| 5053 | + filled_data = numpy_like.fillna(self._data, inplace=inplace, value=value) |
| 5054 | + return pandas.Series(data=filled_data, |
| 5055 | + index=self._index, |
| 5056 | + name=self._name) |
5077 | 5057 |
|
5078 | 5058 | return hpat_pandas_series_fillna_impl |
5079 | 5059 |
|
|
0 commit comments