diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5c670130c..a61d1ec94 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,8 @@ trigger: -- master +- '*' pr: -- master +- '*' jobs: - template: buildscripts/azure/template-windows.yml diff --git a/sdc/functions/numpy_like.py b/sdc/functions/numpy_like.py index af5914d06..54616279f 100644 --- a/sdc/functions/numpy_like.py +++ b/sdc/functions/numpy_like.py @@ -534,26 +534,61 @@ def sdc_fillna_overload(self, inplace=False, value=None): dtype = self.dtype isnan = get_isnan(dtype) + if ( (isinstance(inplace, types.Literal) and inplace.literal_value == True) or # noqa (isinstance(inplace, bool) and inplace == True) # noqa ): + + def sdc_fillna_inplace_noop(self, inplace=False, value=None): + return None + + if isinstance(value, (types.NoneType, types.Omitted)) or value is None: + return sdc_fillna_inplace_noop + if isinstance(dtype, (types.Integer, types.Boolean)): - def sdc_fillna_inplace_int_impl(self, inplace=False, value=None): + return sdc_fillna_inplace_noop + + if isinstance(dtype, types.Float): + def sdc_fillna_inplace_float_impl(self, inplace=False, value=None): + _value = np.nan if value is None else value + length = len(self) + for i in prange(length): + if isnan(self[i]): + self[i] = _value return None - return sdc_fillna_inplace_int_impl + return sdc_fillna_inplace_float_impl - def sdc_fillna_inplace_float_impl(self, inplace=False, value=None): - length = len(self) - for i in prange(length): - if isnan(self[i]): - self[i] = value + if isinstance(dtype, types.UnicodeType): + # TO-DO: not supported, since no generic setitem for StringArray return None - return sdc_fillna_inplace_float_impl - else: + + def sdc_fillna_noop(self, inplace=False, value=None): + return copy(self) + + if isinstance(value, (types.NoneType, types.Omitted)) or value is None: + return sdc_fillna_noop + + if isinstance(dtype, (types.Integer, types.Boolean)): + return sdc_fillna_noop + + if isinstance(dtype, types.Float): + def sdc_fillna_impl(self, inplace=False, value=None): + _value = np.nan if value is None else value + length = len(self) + filled_data = numpy.empty(length, dtype=dtype) + for i in prange(length): + if isnan(self[i]): + filled_data[i] = _value + else: + filled_data[i] = self[i] + return filled_data + + return sdc_fillna_impl + if isinstance(self.dtype, types.UnicodeType): def sdc_fillna_str_impl(self, inplace=False, value=None): n = len(self) @@ -562,9 +597,9 @@ def sdc_fillna_str_impl(self, inplace=False, value=None): for i in prange(n): s = self[i] if sdc.hiframes.api.isna(self, i): - num_chars += len(value) + num_chars += get_utf8_size(value) else: - num_chars += len(s) + num_chars += get_utf8_size(s) filled_data = pre_alloc_string_array(n, num_chars) for i in prange(n): @@ -576,24 +611,6 @@ def sdc_fillna_str_impl(self, inplace=False, value=None): return sdc_fillna_str_impl - if isinstance(dtype, (types.Integer, types.Boolean)): - def sdc_fillna_int_impl(self, inplace=False, value=None): - return copy(self) - - return sdc_fillna_int_impl - - def sdc_fillna_impl(self, inplace=False, value=None): - length = len(self) - filled_data = numpy.empty(length, dtype=dtype) - for i in prange(length): - if isnan(self[i]): - filled_data[i] = value - else: - filled_data[i] = self[i] - return filled_data - - return sdc_fillna_impl - def nanmin(a): pass diff --git a/sdc/sdc_autogenerated.py b/sdc/sdc_autogenerated.py index 9fbb2eed7..475f1046e 100644 --- a/sdc/sdc_autogenerated.py +++ b/sdc/sdc_autogenerated.py @@ -81,7 +81,6 @@ def sdc_pandas_series_add(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method add().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -118,22 +117,20 @@ def sdc_pandas_series_add(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_add_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data + numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) + other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -144,10 +141,8 @@ def _series_add_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_add_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -158,6 +153,7 @@ def _series_add_none_indexes_impl(self, other, level=None, fill_value=None, axis min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -186,13 +182,9 @@ def _series_add_none_indexes_impl(self, other, level=None, fill_value=None, axis numba_index_common_dtype = self_index_dtype def _series_add_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -213,6 +205,7 @@ def _series_add_common_impl(self, other, level=None, fill_value=None, axis=0): result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -257,7 +250,6 @@ def sdc_pandas_series_div(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method div().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -294,22 +286,20 @@ def sdc_pandas_series_div(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_div_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data / numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) / other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -320,10 +310,8 @@ def _series_div_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_div_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -334,6 +322,7 @@ def _series_div_none_indexes_impl(self, other, level=None, fill_value=None, axis min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -362,13 +351,9 @@ def _series_div_none_indexes_impl(self, other, level=None, fill_value=None, axis numba_index_common_dtype = self_index_dtype def _series_div_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -389,6 +374,7 @@ def _series_div_common_impl(self, other, level=None, fill_value=None, axis=0): result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -433,7 +419,6 @@ def sdc_pandas_series_sub(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method sub().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -470,22 +455,20 @@ def sdc_pandas_series_sub(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_sub_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data - numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) - other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -496,10 +479,8 @@ def _series_sub_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_sub_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -510,6 +491,7 @@ def _series_sub_none_indexes_impl(self, other, level=None, fill_value=None, axis min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -538,13 +520,9 @@ def _series_sub_none_indexes_impl(self, other, level=None, fill_value=None, axis numba_index_common_dtype = self_index_dtype def _series_sub_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -565,6 +543,7 @@ def _series_sub_common_impl(self, other, level=None, fill_value=None, axis=0): result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -609,7 +588,6 @@ def sdc_pandas_series_mul(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method mul().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -646,22 +624,20 @@ def sdc_pandas_series_mul(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_mul_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data * numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) * other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -672,10 +648,8 @@ def _series_mul_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_mul_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -686,6 +660,7 @@ def _series_mul_none_indexes_impl(self, other, level=None, fill_value=None, axis min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -714,13 +689,9 @@ def _series_mul_none_indexes_impl(self, other, level=None, fill_value=None, axis numba_index_common_dtype = self_index_dtype def _series_mul_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -741,6 +712,7 @@ def _series_mul_common_impl(self, other, level=None, fill_value=None, axis=0): result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -785,7 +757,6 @@ def sdc_pandas_series_truediv(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method truediv().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -822,22 +793,20 @@ def sdc_pandas_series_truediv(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_truediv_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data / numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) / other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -848,10 +817,8 @@ def _series_truediv_scalar_impl(self, other, level=None, fill_value=None, axis=0 # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_truediv_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -862,6 +829,7 @@ def _series_truediv_none_indexes_impl(self, other, level=None, fill_value=None, min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -890,13 +858,9 @@ def _series_truediv_none_indexes_impl(self, other, level=None, fill_value=None, numba_index_common_dtype = self_index_dtype def _series_truediv_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -917,6 +881,7 @@ def _series_truediv_common_impl(self, other, level=None, fill_value=None, axis=0 result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -961,7 +926,6 @@ def sdc_pandas_series_floordiv(self, other, level=None, fill_value=None, axis=0) """ _func_name = 'Method floordiv().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -998,22 +962,20 @@ def sdc_pandas_series_floordiv(self, other, level=None, fill_value=None, axis=0) if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_floordiv_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data // numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) // other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -1024,10 +986,8 @@ def _series_floordiv_scalar_impl(self, other, level=None, fill_value=None, axis= # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_floordiv_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -1038,6 +998,7 @@ def _series_floordiv_none_indexes_impl(self, other, level=None, fill_value=None, min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -1066,13 +1027,9 @@ def _series_floordiv_none_indexes_impl(self, other, level=None, fill_value=None, numba_index_common_dtype = self_index_dtype def _series_floordiv_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -1093,6 +1050,7 @@ def _series_floordiv_common_impl(self, other, level=None, fill_value=None, axis= result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -1137,7 +1095,6 @@ def sdc_pandas_series_mod(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method mod().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -1174,22 +1131,20 @@ def sdc_pandas_series_mod(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_mod_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data % numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) % other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -1200,10 +1155,8 @@ def _series_mod_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_mod_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -1214,6 +1167,7 @@ def _series_mod_none_indexes_impl(self, other, level=None, fill_value=None, axis min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -1242,13 +1196,9 @@ def _series_mod_none_indexes_impl(self, other, level=None, fill_value=None, axis numba_index_common_dtype = self_index_dtype def _series_mod_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -1269,6 +1219,7 @@ def _series_mod_common_impl(self, other, level=None, fill_value=None, axis=0): result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -1313,7 +1264,6 @@ def sdc_pandas_series_pow(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method pow().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -1350,22 +1300,20 @@ def sdc_pandas_series_pow(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_pow_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data ** numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) ** other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -1376,10 +1324,8 @@ def _series_pow_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_pow_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -1390,6 +1336,7 @@ def _series_pow_none_indexes_impl(self, other, level=None, fill_value=None, axis min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -1418,13 +1365,9 @@ def _series_pow_none_indexes_impl(self, other, level=None, fill_value=None, axis numba_index_common_dtype = self_index_dtype def _series_pow_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -1445,6 +1388,7 @@ def _series_pow_common_impl(self, other, level=None, fill_value=None, axis=0): result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -1530,12 +1474,10 @@ def sdc_pandas_series_lt(self, other, level=None, fill_value=None, axis=0): if not operands_are_series: def _series_lt_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) return pandas.Series(self._data < other, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) return pandas.Series(self < other._data, index=other._index, name=other._name) return _series_lt_scalar_impl @@ -1545,9 +1487,8 @@ def _series_lt_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_lt_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_size, right_size = len(self._data), len(other._data) if (left_size == right_size): return pandas.Series(self._data < other._data) @@ -1557,21 +1498,18 @@ def _series_lt_none_indexes_impl(self, other, level=None, fill_value=None, axis= return _series_lt_none_indexes_impl else: left_index_is_range = isinstance(self.index, (RangeIndexType, types.NoneType)) - self_index_dtype = RangeIndexType.dtype if isinstance(self.index, types.NoneType) else self.index.dtype - other_index_dtype = RangeIndexType.dtype if isinstance(other.index, types.NoneType) else other.index.dtype - index_dtypes_match = self_index_dtype == other_index_dtype + index_dtypes_match = self.index.dtype == other.index.dtype if not index_dtypes_match: numba_index_common_dtype = find_common_dtype_from_numpy_dtypes( - [self_index_dtype, other_index_dtype], []) + [self.index.dtype, other.index.dtype], []) else: - numba_index_common_dtype = self_index_dtype + numba_index_common_dtype = self.index.dtype def _series_lt_common_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_index, right_index = self.index, other.index + if (left_index is right_index or numpy_like.array_equal(left_index, right_index)): if index_dtypes_match == False: # noqa new_index = numpy_like.astype(left_index, numba_index_common_dtype) @@ -1660,12 +1598,10 @@ def sdc_pandas_series_gt(self, other, level=None, fill_value=None, axis=0): if not operands_are_series: def _series_gt_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) return pandas.Series(self._data > other, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) return pandas.Series(self > other._data, index=other._index, name=other._name) return _series_gt_scalar_impl @@ -1675,9 +1611,8 @@ def _series_gt_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_gt_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_size, right_size = len(self._data), len(other._data) if (left_size == right_size): return pandas.Series(self._data > other._data) @@ -1687,21 +1622,18 @@ def _series_gt_none_indexes_impl(self, other, level=None, fill_value=None, axis= return _series_gt_none_indexes_impl else: left_index_is_range = isinstance(self.index, (RangeIndexType, types.NoneType)) - self_index_dtype = RangeIndexType.dtype if isinstance(self.index, types.NoneType) else self.index.dtype - other_index_dtype = RangeIndexType.dtype if isinstance(other.index, types.NoneType) else other.index.dtype - index_dtypes_match = self_index_dtype == other_index_dtype + index_dtypes_match = self.index.dtype == other.index.dtype if not index_dtypes_match: numba_index_common_dtype = find_common_dtype_from_numpy_dtypes( - [self_index_dtype, other_index_dtype], []) + [self.index.dtype, other.index.dtype], []) else: - numba_index_common_dtype = self_index_dtype + numba_index_common_dtype = self.index.dtype def _series_gt_common_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_index, right_index = self.index, other.index + if (left_index is right_index or numpy_like.array_equal(left_index, right_index)): if index_dtypes_match == False: # noqa new_index = numpy_like.astype(left_index, numba_index_common_dtype) @@ -1790,12 +1722,10 @@ def sdc_pandas_series_le(self, other, level=None, fill_value=None, axis=0): if not operands_are_series: def _series_le_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) return pandas.Series(self._data <= other, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) return pandas.Series(self <= other._data, index=other._index, name=other._name) return _series_le_scalar_impl @@ -1805,9 +1735,8 @@ def _series_le_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_le_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_size, right_size = len(self._data), len(other._data) if (left_size == right_size): return pandas.Series(self._data <= other._data) @@ -1817,21 +1746,18 @@ def _series_le_none_indexes_impl(self, other, level=None, fill_value=None, axis= return _series_le_none_indexes_impl else: left_index_is_range = isinstance(self.index, (RangeIndexType, types.NoneType)) - self_index_dtype = RangeIndexType.dtype if isinstance(self.index, types.NoneType) else self.index.dtype - other_index_dtype = RangeIndexType.dtype if isinstance(other.index, types.NoneType) else other.index.dtype - index_dtypes_match = self_index_dtype == other_index_dtype + index_dtypes_match = self.index.dtype == other.index.dtype if not index_dtypes_match: numba_index_common_dtype = find_common_dtype_from_numpy_dtypes( - [self_index_dtype, other_index_dtype], []) + [self.index.dtype, other.index.dtype], []) else: - numba_index_common_dtype = self_index_dtype + numba_index_common_dtype = self.index.dtype def _series_le_common_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_index, right_index = self.index, other.index + if (left_index is right_index or numpy_like.array_equal(left_index, right_index)): if index_dtypes_match == False: # noqa new_index = numpy_like.astype(left_index, numba_index_common_dtype) @@ -1920,12 +1846,10 @@ def sdc_pandas_series_ge(self, other, level=None, fill_value=None, axis=0): if not operands_are_series: def _series_ge_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) return pandas.Series(self._data >= other, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) return pandas.Series(self >= other._data, index=other._index, name=other._name) return _series_ge_scalar_impl @@ -1935,9 +1859,8 @@ def _series_ge_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_ge_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_size, right_size = len(self._data), len(other._data) if (left_size == right_size): return pandas.Series(self._data >= other._data) @@ -1947,21 +1870,18 @@ def _series_ge_none_indexes_impl(self, other, level=None, fill_value=None, axis= return _series_ge_none_indexes_impl else: left_index_is_range = isinstance(self.index, (RangeIndexType, types.NoneType)) - self_index_dtype = RangeIndexType.dtype if isinstance(self.index, types.NoneType) else self.index.dtype - other_index_dtype = RangeIndexType.dtype if isinstance(other.index, types.NoneType) else other.index.dtype - index_dtypes_match = self_index_dtype == other_index_dtype + index_dtypes_match = self.index.dtype == other.index.dtype if not index_dtypes_match: numba_index_common_dtype = find_common_dtype_from_numpy_dtypes( - [self_index_dtype, other_index_dtype], []) + [self.index.dtype, other.index.dtype], []) else: - numba_index_common_dtype = self_index_dtype + numba_index_common_dtype = self.index.dtype def _series_ge_common_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_index, right_index = self.index, other.index + if (left_index is right_index or numpy_like.array_equal(left_index, right_index)): if index_dtypes_match == False: # noqa new_index = numpy_like.astype(left_index, numba_index_common_dtype) @@ -2050,12 +1970,10 @@ def sdc_pandas_series_ne(self, other, level=None, fill_value=None, axis=0): if not operands_are_series: def _series_ne_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) return pandas.Series(self._data != other, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) return pandas.Series(self != other._data, index=other._index, name=other._name) return _series_ne_scalar_impl @@ -2065,9 +1983,8 @@ def _series_ne_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_ne_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_size, right_size = len(self._data), len(other._data) if (left_size == right_size): return pandas.Series(self._data != other._data) @@ -2077,21 +1994,18 @@ def _series_ne_none_indexes_impl(self, other, level=None, fill_value=None, axis= return _series_ne_none_indexes_impl else: left_index_is_range = isinstance(self.index, (RangeIndexType, types.NoneType)) - self_index_dtype = RangeIndexType.dtype if isinstance(self.index, types.NoneType) else self.index.dtype - other_index_dtype = RangeIndexType.dtype if isinstance(other.index, types.NoneType) else other.index.dtype - index_dtypes_match = self_index_dtype == other_index_dtype + index_dtypes_match = self.index.dtype == other.index.dtype if not index_dtypes_match: numba_index_common_dtype = find_common_dtype_from_numpy_dtypes( - [self_index_dtype, other_index_dtype], []) + [self.index.dtype, other.index.dtype], []) else: - numba_index_common_dtype = self_index_dtype + numba_index_common_dtype = self.index.dtype def _series_ne_common_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_index, right_index = self.index, other.index + if (left_index is right_index or numpy_like.array_equal(left_index, right_index)): if index_dtypes_match == False: # noqa new_index = numpy_like.astype(left_index, numba_index_common_dtype) @@ -2180,12 +2094,10 @@ def sdc_pandas_series_eq(self, other, level=None, fill_value=None, axis=0): if not operands_are_series: def _series_eq_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) return pandas.Series(self._data == other, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) return pandas.Series(self == other._data, index=other._index, name=other._name) return _series_eq_scalar_impl @@ -2195,9 +2107,8 @@ def _series_eq_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_eq_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_size, right_size = len(self._data), len(other._data) if (left_size == right_size): return pandas.Series(self._data == other._data) @@ -2207,21 +2118,18 @@ def _series_eq_none_indexes_impl(self, other, level=None, fill_value=None, axis= return _series_eq_none_indexes_impl else: left_index_is_range = isinstance(self.index, (RangeIndexType, types.NoneType)) - self_index_dtype = RangeIndexType.dtype if isinstance(self.index, types.NoneType) else self.index.dtype - other_index_dtype = RangeIndexType.dtype if isinstance(other.index, types.NoneType) else other.index.dtype - index_dtypes_match = self_index_dtype == other_index_dtype + index_dtypes_match = self.index.dtype == other.index.dtype if not index_dtypes_match: numba_index_common_dtype = find_common_dtype_from_numpy_dtypes( - [self_index_dtype, other_index_dtype], []) + [self.index.dtype, other.index.dtype], []) else: - numba_index_common_dtype = self_index_dtype + numba_index_common_dtype = self.index.dtype def _series_eq_common_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_index, right_index = self.index, other.index + if (left_index is right_index or numpy_like.array_equal(left_index, right_index)): if index_dtypes_match == False: # noqa new_index = numpy_like.astype(left_index, numba_index_common_dtype) @@ -2264,7 +2172,7 @@ def sdc_pandas_series_operator_add(self, other): The result of the operation """ - _func_name = 'Method comp_add().' + _func_name = 'Operator add().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -2329,7 +2237,7 @@ def sdc_pandas_series_operator_sub(self, other): The result of the operation """ - _func_name = 'Method comp_sub().' + _func_name = 'Operator sub().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -2394,7 +2302,7 @@ def sdc_pandas_series_operator_mul(self, other): The result of the operation """ - _func_name = 'Method comp_mul().' + _func_name = 'Operator mul().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -2459,7 +2367,7 @@ def sdc_pandas_series_operator_truediv(self, other): The result of the operation """ - _func_name = 'Method comp_truediv().' + _func_name = 'Operator truediv().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -2524,7 +2432,7 @@ def sdc_pandas_series_operator_floordiv(self, other): The result of the operation """ - _func_name = 'Method comp_floordiv().' + _func_name = 'Operator floordiv().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -2589,7 +2497,7 @@ def sdc_pandas_series_operator_mod(self, other): The result of the operation """ - _func_name = 'Method comp_mod().' + _func_name = 'Operator mod().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -2654,7 +2562,7 @@ def sdc_pandas_series_operator_pow(self, other): The result of the operation """ - _func_name = 'Method comp_pow().' + _func_name = 'Operator pow().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): diff --git a/sdc/sdc_function_templates.py b/sdc/sdc_function_templates.py index 515447282..627cf75e8 100644 --- a/sdc/sdc_function_templates.py +++ b/sdc/sdc_function_templates.py @@ -81,7 +81,6 @@ def sdc_pandas_series_binop(self, other, level=None, fill_value=None, axis=0): """ _func_name = 'Method binop().' - ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): @@ -118,22 +117,20 @@ def sdc_pandas_series_binop(self, other, level=None, fill_value=None, axis=0): if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None: ty_checker.raise_exc(fill_value, 'number', 'fill_value') + fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None if not isinstance(axis, types.Omitted) and axis != 0: ty_checker.raise_exc(axis, 'int', 'axis') - fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None # specializations for numeric series only if not operands_are_series: def _series_binop_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) result_data = numpy.empty(len(self._data), dtype=numpy.float64) result_data[:] = self._data + numpy.float64(other) return pandas.Series(result_data, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) result_data = numpy.empty(len(other._data), dtype=numpy.float64) result_data[:] = numpy.float64(self) + other._data return pandas.Series(result_data, index=other._index, name=other._name) @@ -144,10 +141,8 @@ def _series_binop_scalar_impl(self, other, level=None, fill_value=None, axis=0): # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_binop_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if (len(self._data) == len(other._data)): result_data = numpy_like.astype(self._data, numpy.float64) @@ -158,6 +153,7 @@ def _series_binop_none_indexes_impl(self, other, level=None, fill_value=None, ax min_data_size = min(left_size, right_size) max_data_size = max(left_size, right_size) result_data = numpy.empty(max_data_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa if (left_size == min_data_size): result_data[:min_data_size] = self._data for i in range(min_data_size, len(result_data)): @@ -186,13 +182,9 @@ def _series_binop_none_indexes_impl(self, other, level=None, fill_value=None, ax numba_index_common_dtype = self_index_dtype def _series_binop_common_impl(self, other, level=None, fill_value=None, axis=0): - - _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - left_index, right_index = self.index, other.index + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) if check_index_equal == True: # noqa equal_indexes = numpy_like.array_equal(left_index, right_index) else: @@ -213,6 +205,7 @@ def _series_binop_common_impl(self, other, level=None, fill_value=None, axis=0): result_size = len(joined_index) left_values = numpy.empty(result_size, dtype=numpy.float64) right_values = numpy.empty(result_size, dtype=numpy.float64) + _fill_value = numpy.nan if fill_value_is_none == True else fill_value # noqa for i in range(result_size): left_pos, right_pos = left_indexer[i], right_indexer[i] left_values[i] = self._data[left_pos] if left_pos != -1 else _fill_value @@ -297,12 +290,10 @@ def sdc_pandas_series_comp_binop(self, other, level=None, fill_value=None, axis= if not operands_are_series: def _series_comp_binop_scalar_impl(self, other, level=None, fill_value=None, axis=0): if self_is_series == True: # noqa - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) return pandas.Series(self._data < other, index=self._index, name=self._name) else: - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) return pandas.Series(self < other._data, index=other._index, name=other._name) return _series_comp_binop_scalar_impl @@ -312,9 +303,8 @@ def _series_comp_binop_scalar_impl(self, other, level=None, fill_value=None, axi # optimization for series with default indexes, that can be aligned differently if (isinstance(self.index, types.NoneType) and isinstance(other.index, types.NoneType)): def _series_comp_binop_none_indexes_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_size, right_size = len(self._data), len(other._data) if (left_size == right_size): return pandas.Series(self._data < other._data) @@ -332,11 +322,10 @@ def _series_comp_binop_none_indexes_impl(self, other, level=None, fill_value=Non numba_index_common_dtype = self.index.dtype def _series_comp_binop_common_impl(self, other, level=None, fill_value=None, axis=0): - if not (fill_value is None or numpy.isnan(fill_value)): - numpy_like.fillna(self._data, inplace=True, value=fill_value) - numpy_like.fillna(other._data, inplace=True, value=fill_value) - + numpy_like.fillna(self._data, inplace=True, value=fill_value) + numpy_like.fillna(other._data, inplace=True, value=fill_value) left_index, right_index = self.index, other.index + if (left_index is right_index or numpy_like.array_equal(left_index, right_index)): if index_dtypes_match == False: # noqa new_index = numpy_like.astype(left_index, numba_index_common_dtype) @@ -378,7 +367,7 @@ def sdc_pandas_series_operator_binop(self, other): The result of the operation """ - _func_name = 'Method comp_binop().' + _func_name = 'Operator binop().' ty_checker = TypeChecker(_func_name) self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType) if not (self_is_series or other_is_series): diff --git a/sdc/tests/gen_test_data.py b/sdc/tests/gen_test_data.py index fa5fbba0b..ee20249f5 100644 --- a/sdc/tests/gen_test_data.py +++ b/sdc/tests/gen_test_data.py @@ -120,16 +120,6 @@ def generate_csv_data(): with open("csv_data_date1.csv", "w") as f: f.write(data) - # generated data for parallel merge_asof testing - df1 = pd.DataFrame({'time': pd.DatetimeIndex( - ['2017-01-03', '2017-01-06', '2017-02-15', '2017-02-21']), - 'B': [4, 5, 9, 6]}) - df2 = pd.DataFrame({'time': pd.DatetimeIndex( - ['2017-01-01', '2017-01-14', '2017-01-16', '2017-02-23', '2017-02-23', - '2017-02-25']), 'A': [2, 3, 7, 8, 9, 10]}) - df1.to_parquet("asof1.pq") - df2.to_parquet("asof2.pq") - def generate_other_data(): df = pd.DataFrame({'A': ['bc'] + ["a"] * 3 + ["bc"] * 3 + ['a'], 'B': [-8, 1, 2, 3, 1, 5, 6, 7]}) diff --git a/sdc/tests/test_sdc_numpy.py b/sdc/tests/test_sdc_numpy.py index ff3cbef47..8a4bff36f 100644 --- a/sdc/tests/test_sdc_numpy.py +++ b/sdc/tests/test_sdc_numpy.py @@ -30,6 +30,7 @@ import pandas as pd import sdc import unittest +from itertools import product from sdc.str_arr_ext import StringArray from sdc.str_ext import std_str_to_unicode, unicode_to_std_str @@ -368,6 +369,94 @@ def sdc_impl(a): with self.subTest(data=case): np.testing.assert_array_equal(ref_impl(array0), sdc_func(array1)) + def _test_fillna_numeric(self, pyfunc, cfunc, inplace): + data_to_test = [ + [True, False, False, True, True], + [5, 2, 0, 333, -4], + [3.3, 5.4, 7.9], + [3.3, 5.4, np.nan, 7.9, np.nan], + ] + values_to_test = [ + None, + np.nan, + 2.1, + 2 + ] + + for data, value in product(data_to_test, values_to_test): + a1 = np.asarray(data) + a2 = pd.Series(np.copy(a1)) if inplace else pd.Series(a1) + + with self.subTest(data=data, value=value): + result = cfunc(a1, value) + result_ref = pyfunc(a2, value) + if inplace: + result, result_ref = a1, a2 + np.testing.assert_array_equal(result, result_ref) + + def test_fillna_numeric_inplace_false(self): + def ref_impl(S, value): + if value is None: + return S.values.copy() + else: + return S.fillna(value=value, inplace=False).values + + def sdc_impl(a, value): + return numpy_like.fillna(a, inplace=False, value=value) + sdc_func = self.jit(sdc_impl) + + self._test_fillna_numeric(ref_impl, sdc_func, inplace=False) + + def test_fillna_numeric_inplace_true(self): + def ref_impl(S, value): + if value is None: + return None + else: + S.fillna(value=value, inplace=True) + return None + + def sdc_impl(a, value): + return numpy_like.fillna(a, inplace=True, value=value) + sdc_func = self.jit(sdc_impl) + + self._test_fillna_numeric(ref_impl, sdc_func, inplace=True) + + def test_fillna_str_inplace_false(self): + def ref_impl(S, value): + if value is None: + return S.values.copy() + else: + return S.fillna(value=value, inplace=False).values + + def sdc_impl(S, value): + str_arr = S.values + return numpy_like.fillna(str_arr, inplace=False, value=value) + sdc_func = self.jit(sdc_impl) + + data_to_test = [ + ['a', 'b', 'c', 'd'], + ['a', 'b', None, 'c', None, 'd'], + ] + values_to_test = [ + None, + '', + 'asd' + ] + for data, value in product(data_to_test, values_to_test): + S = pd.Series(data) + with self.subTest(data=data, value=value): + result = sdc_func(S, value) + result_ref = ref_impl(S, value) + + # FIXME: str_arr unifies None with np.nan and StringArray boxing always return np.nan + # to avoid mismatch in results for fill value == None use custom comparing func + def is_same_unify_nones(a, b): + return a == b or ((a is None or np.isnan(a)) and (b is None or np.isnan(b))) + cmp_result = np.asarray( + list(map(is_same_unify_nones, result, result_ref)) + ) + self.assertEqual(np.all(cmp_result), True) + class TestArrayReductions(TestCase): diff --git a/sdc/tests/test_series.py b/sdc/tests/test_series.py index 51b262509..ed8d76d32 100644 --- a/sdc/tests/test_series.py +++ b/sdc/tests/test_series.py @@ -2447,7 +2447,7 @@ def _check_mean(self, pyfunc, *args): if np.isnan(actual) or np.isnan(expected): self.assertEqual(np.isnan(actual), np.isnan(expected)) else: - np.testing.assert_array_almost_equal(actual, expected) + np.testing.assert_almost_equal(actual, expected) def test_series_mean(self): def test_impl(S):