Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 6d77677

Browse files
authored
Series.add / Series.lt with fill_value (#655)
1 parent b741040 commit 6d77677

File tree

7 files changed

+2104
-1479
lines changed

7 files changed

+2104
-1479
lines changed

buildscripts/autogen_sources.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
arithmetic_binops_symbols = {
7979
'add': '+',
80+
'div': '/',
8081
'sub': '-',
8182
'mul': '*',
8283
'truediv': '/',
@@ -117,9 +118,11 @@
117118
import_section_text = ''.join(module_text_lines[imports_start_line: import_end_line + 1])
118119

119120
# read function templates for arithmetic and comparison operators from templates module
120-
template_series_arithmetic_binop = inspect.getsource(templates_module.sdc_pandas_series_operator_binop)
121-
template_series_comparison_binop = inspect.getsource(templates_module.sdc_pandas_series_operator_comp_binop)
122-
template_str_arr_comparison_binop = inspect.getsource(templates_module.sdc_str_arr_operator_comp_binop)
121+
template_series_binop = inspect.getsource(templates_module.sdc_pandas_series_binop)
122+
template_series_comp_binop = inspect.getsource(templates_module.sdc_pandas_series_comp_binop)
123+
template_series_operator = inspect.getsource(templates_module.sdc_pandas_series_operator_binop)
124+
template_series_comp_operator = inspect.getsource(templates_module.sdc_pandas_series_operator_comp_binop)
125+
template_str_arr_comp_binop = inspect.getsource(templates_module.sdc_str_arr_operator_comp_binop)
123126

124127
exit_status = -1
125128
try:
@@ -133,19 +136,32 @@
133136
# certaing modifications are needed to be applied for templates, so
134137
# verify correctness of produced code manually
135138
for name in arithmetic_binops_symbols:
136-
func_text = template_series_arithmetic_binop.replace('binop', name)
139+
func_text = template_series_binop.replace('binop', name)
137140
func_text = func_text.replace(' + ', f' {arithmetic_binops_symbols[name]} ')
138-
func_text = func_text.replace('def ', f'@sdc_overload(operator.{name})\ndef ', 1)
141+
func_text = func_text.replace('def ', f"@sdc_overload_method(SeriesType, '{name}')\ndef ", 1)
139142
file.write(f'\n\n{func_text}')
140143

141144
for name in comparison_binops_symbols:
142-
func_text = template_series_comparison_binop.replace('comp_binop', name)
145+
func_text = template_series_comp_binop.replace('comp_binop', name)
146+
func_text = func_text.replace(' < ', f' {comparison_binops_symbols[name]} ')
147+
func_text = func_text.replace('def ', f"@sdc_overload_method(SeriesType, '{name}')\ndef ", 1)
148+
file.write(f'\n\n{func_text}')
149+
150+
for name in arithmetic_binops_symbols:
151+
if name != "div":
152+
func_text = template_series_operator.replace('binop', name)
153+
func_text = func_text.replace(' + ', f' {arithmetic_binops_symbols[name]} ')
154+
func_text = func_text.replace('def ', f'@sdc_overload(operator.{name})\ndef ', 1)
155+
file.write(f'\n\n{func_text}')
156+
157+
for name in comparison_binops_symbols:
158+
func_text = template_series_comp_operator.replace('comp_binop', name)
143159
func_text = func_text.replace(' < ', f' {comparison_binops_symbols[name]} ')
144160
func_text = func_text.replace('def ', f'@sdc_overload(operator.{name})\ndef ', 1)
145161
file.write(f'\n\n{func_text}')
146162

147163
for name in comparison_binops_symbols:
148-
func_text = template_str_arr_comparison_binop.replace('comp_binop', name)
164+
func_text = template_str_arr_comp_binop.replace('comp_binop', name)
149165
func_text = func_text.replace(' < ', f' {comparison_binops_symbols[name]} ')
150166
if name == 'ne':
151167
func_text = func_text.replace('and not', 'or')

sdc/datatypes/common_functions.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,21 @@ def sdc_join_series_indexes_impl(left, right):
228228
ridx = numpy.empty(est_total_size, numpy.int64)
229229
joined = numpy.empty(est_total_size, numba_common_dtype)
230230

231+
left_nan = []
232+
right_nan = []
233+
for i in range(lsize):
234+
if numpy.isnan(left[i]):
235+
left_nan.append(i)
236+
for i in range(rsize):
237+
if numpy.isnan(right[i]):
238+
right_nan.append(i)
239+
231240
# sort arrays saving the old positions
232241
sorted_left = numpy.argsort(left, kind='mergesort')
233242
sorted_right = numpy.argsort(right, kind='mergesort')
243+
# put the position of the nans in an increasing sequence
244+
sorted_left[lsize-len(left_nan):] = left_nan
245+
sorted_right[rsize-len(right_nan):] = right_nan
234246

235247
i, j, k = 0, 0, 0
236248
while (i < lsize and j < rsize):
@@ -241,13 +253,13 @@ def sdc_join_series_indexes_impl(left, right):
241253
left_index = left[sorted_left[i]]
242254
right_index = right[sorted_right[j]]
243255

244-
if (left_index < right_index):
256+
if (left_index < right_index) or numpy.isnan(right_index):
245257
joined[k] = left_index
246258
lidx[k] = sorted_left[i]
247259
ridx[k] = -1
248260
i += 1
249261
k += 1
250-
elif (left_index > right_index):
262+
elif (left_index > right_index) or numpy.isnan(left_index):
251263
joined[k] = right_index
252264
lidx[k] = -1
253265
ridx[k] = sorted_right[j]

0 commit comments

Comments
 (0)