|
30 | 30 | import pandas as pd |
31 | 31 |
|
32 | 32 | from numba import types |
33 | | -from numba.typed import Dict |
| 33 | +from numba.typed import Dict, List |
34 | 34 | from numba.typed.typedobjectutils import _nonoptional |
35 | 35 |
|
36 | 36 | from sdc.utilities.sdc_typing_utils import sdc_pandas_index_types, sdc_old_index_types |
37 | 37 | from sdc.datatypes.indexes import * |
38 | | -from sdc.utilities.utils import sdc_overload_method, sdc_overload |
| 38 | +from sdc.utilities.utils import sdc_overload |
39 | 39 | from sdc.utilities.sdc_typing_utils import ( |
40 | 40 | find_index_common_dtype, |
41 | 41 | sdc_indexes_wo_values_cache, |
@@ -96,7 +96,9 @@ def sdc_indexes_operator_eq_ovld(self, other): |
96 | 96 | # TO-DO: this is for numeric indexes only now, extend to string-index when it's added |
97 | 97 | use_self_values = isinstance(self, sdc_pandas_index_types) and not isinstance(self, types.Array) |
98 | 98 | use_other_values = isinstance(other, sdc_pandas_index_types) and not isinstance(other, types.Array) |
99 | | - one_operand_is_scalar = isinstance(self, types.Number) or isinstance(other, types.Number) |
| 99 | + |
| 100 | + one_operand_is_scalar = (isinstance(other, sdc_pandas_index_types) and self is other.dtype |
| 101 | + or isinstance(self, sdc_pandas_index_types) and other is self.dtype) |
100 | 102 |
|
101 | 103 | def sdc_indexes_operator_eq_impl(self, other): |
102 | 104 |
|
@@ -217,8 +219,8 @@ def pd_fix_indexes_join_overload(joined, indexer1, indexer2): |
217 | 219 | """ Wraps pandas index.join() into new function that returns indexers as arrays and not optional(array) """ |
218 | 220 |
|
219 | 221 | # This function is simply a workaround for problem with parfor lowering |
220 | | - # broken by indexers typed as types.Optional(Array) - FIXME_Numba#XXXX: remove it |
221 | | - # in all places whne parfor issue is fixed |
| 222 | + # broken by indexers typed as types.Optional(Array) - FIXME_Numba#6686: remove it |
| 223 | + # in all places when parfor issue is fixed |
222 | 224 | def pd_fix_indexes_join_impl(joined, indexer1, indexer2): |
223 | 225 | if indexer1 is not None: |
224 | 226 | _indexer1 = _nonoptional(indexer1) |
@@ -282,3 +284,109 @@ def sdc_np_array_overload(A): |
282 | 284 |
|
283 | 285 | if isinstance(A, Int64IndexType): |
284 | 286 | return lambda A: A._data |
| 287 | + |
| 288 | + |
| 289 | +def sdc_indexes_take(self, target): |
| 290 | + pass |
| 291 | + |
| 292 | + |
| 293 | +@sdc_overload(sdc_indexes_take) |
| 294 | +def pd_fix_indexes_take_overload(self, indexes): |
| 295 | + """ Simply workaround for not having take method as unique indexes due to |
| 296 | + the fact that StringArrayType is one of the index types """ |
| 297 | + |
| 298 | + check = isinstance(self, sdc_pandas_index_types) |
| 299 | + if not isinstance(self, sdc_pandas_index_types): |
| 300 | + return None |
| 301 | + |
| 302 | + index_api_supported = not isinstance(self, sdc_old_index_types) |
| 303 | + |
| 304 | + def pd_fix_indexes_take_impl(self, indexes): |
| 305 | + |
| 306 | + if index_api_supported == True: # noqa |
| 307 | + res = self.take(indexes) |
| 308 | + else: |
| 309 | + res = numpy_like.take(self, indexes) |
| 310 | + |
| 311 | + return res |
| 312 | + |
| 313 | + return pd_fix_indexes_take_impl |
| 314 | + |
| 315 | + |
| 316 | +def sdc_indexes_rename(index, name): |
| 317 | + pass |
| 318 | + |
| 319 | + |
| 320 | +@sdc_overload(sdc_indexes_rename) |
| 321 | +def sdc_index_rename_ovld(index, name): |
| 322 | + |
| 323 | + if not isinstance(index, sdc_pandas_index_types): |
| 324 | + return None |
| 325 | + |
| 326 | + if isinstance(index, sdc_old_index_types): |
| 327 | + def sdc_indexes_rename_stub(index, name): |
| 328 | + # cannot rename string or float indexes, TO-DO: StringIndexType |
| 329 | + return index |
| 330 | + return sdc_indexes_rename_stub |
| 331 | + |
| 332 | + if isinstance(index, PositionalIndexType): |
| 333 | + from sdc.extensions.indexes.positional_index_ext import init_positional_index |
| 334 | + |
| 335 | + def sdc_indexes_rename_impl(index, name): |
| 336 | + return init_positional_index(len(index), name) |
| 337 | + return sdc_indexes_rename_impl |
| 338 | + |
| 339 | + elif isinstance(index, RangeIndexType): |
| 340 | + def sdc_indexes_rename_impl(index, name): |
| 341 | + return pd.RangeIndex(index.start, index.stop, index.step, name=name) |
| 342 | + return sdc_indexes_rename_impl |
| 343 | + |
| 344 | + elif isinstance(index, Int64IndexType): |
| 345 | + def sdc_indexes_rename_impl(index, name): |
| 346 | + return pd.Int64Index(index, name=name) |
| 347 | + return sdc_indexes_rename_impl |
| 348 | + |
| 349 | + |
| 350 | +def sdc_indexes_get_name(index): |
| 351 | + pass |
| 352 | + |
| 353 | + |
| 354 | +@sdc_overload(sdc_indexes_get_name) |
| 355 | +def sdc_indexes_get_name_ovld(index): |
| 356 | + |
| 357 | + if (isinstance(index, sdc_pandas_index_types) |
| 358 | + and not isinstance(index, sdc_old_index_types)): |
| 359 | + def sdc_indexes_get_name_impl(index): |
| 360 | + return index.name |
| 361 | + return sdc_indexes_get_name_impl |
| 362 | + |
| 363 | + def sdc_indexes_get_name_stub(index): |
| 364 | + # cannot rename string or float indexes, TO-DO: StringIndexType |
| 365 | + return None |
| 366 | + return sdc_indexes_get_name_stub |
| 367 | + |
| 368 | + |
| 369 | +def sdc_indexes_build_map_positions(self): |
| 370 | + pass |
| 371 | + |
| 372 | + |
| 373 | +@sdc_overload(sdc_indexes_build_map_positions) |
| 374 | +def sdc_indexes_build_map_positions_ovld(self): |
| 375 | + |
| 376 | + indexer_dtype = self.dtype |
| 377 | + indexer_value_type = types.ListType(types.int64) |
| 378 | + |
| 379 | + def sdc_indexes_build_map_positions_impl(self): |
| 380 | + indexer_map = Dict.empty(indexer_dtype, indexer_value_type) |
| 381 | + for i in range(len(self)): |
| 382 | + val = self[i] |
| 383 | + index_list = indexer_map.get(val, None) |
| 384 | + if index_list is None: |
| 385 | + indexer_map[val] = List.empty_list(types.int64) |
| 386 | + indexer_map[val].append(i) |
| 387 | + else: |
| 388 | + index_list.append(i) |
| 389 | + |
| 390 | + return indexer_map |
| 391 | + |
| 392 | + return sdc_indexes_build_map_positions_impl |
0 commit comments