|
77 | 77 |
|
78 | 78 | arithmetic_binops_symbols = { |
79 | 79 | 'add': '+', |
| 80 | + 'div': '/', |
80 | 81 | 'sub': '-', |
81 | 82 | 'mul': '*', |
82 | 83 | 'truediv': '/', |
|
117 | 118 | import_section_text = ''.join(module_text_lines[imports_start_line: import_end_line + 1]) |
118 | 119 |
|
119 | 120 | # 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) |
123 | 126 |
|
124 | 127 | exit_status = -1 |
125 | 128 | try: |
|
133 | 136 | # certaing modifications are needed to be applied for templates, so |
134 | 137 | # verify correctness of produced code manually |
135 | 138 | 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) |
137 | 140 | 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) |
139 | 142 | file.write(f'\n\n{func_text}') |
140 | 143 |
|
141 | 144 | 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) |
143 | 159 | func_text = func_text.replace(' < ', f' {comparison_binops_symbols[name]} ') |
144 | 160 | func_text = func_text.replace('def ', f'@sdc_overload(operator.{name})\ndef ', 1) |
145 | 161 | file.write(f'\n\n{func_text}') |
146 | 162 |
|
147 | 163 | 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) |
149 | 165 | func_text = func_text.replace(' < ', f' {comparison_binops_symbols[name]} ') |
150 | 166 | if name == 'ne': |
151 | 167 | func_text = func_text.replace('and not', 'or') |
|
0 commit comments