|
33 | 33 |
|
34 | 34 | import numba |
35 | 35 | import numpy |
| 36 | +import pandas |
36 | 37 | import numpy as np |
37 | 38 |
|
38 | 39 | from numba import types, jit, prange, numpy_support, literally |
|
43 | 44 | from sdc.utilities.sdc_typing_utils import TypeChecker |
44 | 45 | from sdc.str_arr_ext import (StringArrayType, pre_alloc_string_array, get_utf8_size, str_arr_is_na) |
45 | 46 | from sdc.utilities.utils import sdc_overload, sdc_register_jitable |
| 47 | +from sdc.utilities.prange_utils import parallel_chunks |
46 | 48 |
|
47 | 49 |
|
48 | 50 | def astype(self, dtype): |
@@ -475,6 +477,49 @@ def nanprod_impl(a): |
475 | 477 | return nanprod_impl |
476 | 478 |
|
477 | 479 |
|
| 480 | +def dropna(arr, idx, name): |
| 481 | + pass |
| 482 | + |
| 483 | + |
| 484 | +@sdc_overload(dropna) |
| 485 | +def dropna_overload(arr, idx, name): |
| 486 | + dtype = arr.dtype |
| 487 | + dtype_idx = idx.dtype |
| 488 | + isnan = get_isnan(dtype) |
| 489 | + |
| 490 | + def dropna_impl(arr, idx, name): |
| 491 | + chunks = parallel_chunks(len(arr)) |
| 492 | + arr_len = numpy.empty(len(chunks), dtype=numpy.int64) |
| 493 | + length = 0 |
| 494 | + |
| 495 | + for i in prange(len(chunks)): |
| 496 | + chunk = chunks[i] |
| 497 | + res = 0 |
| 498 | + for j in range(chunk.start, chunk.stop): |
| 499 | + if not isnan(arr[j]): |
| 500 | + res += 1 |
| 501 | + length += res |
| 502 | + arr_len[i] = res |
| 503 | + |
| 504 | + result_data = numpy.empty(shape=length, dtype=dtype) |
| 505 | + result_index = numpy.empty(shape=length, dtype=dtype_idx) |
| 506 | + for i in prange(len(chunks)): |
| 507 | + chunk = chunks[i] |
| 508 | + new_start = int(sum(arr_len[0:i])) |
| 509 | + new_stop = new_start + arr_len[i] |
| 510 | + current_pos = new_start |
| 511 | + |
| 512 | + for j in range(chunk.start, chunk.stop): |
| 513 | + if not isnan(arr[j]): |
| 514 | + result_data[current_pos] = arr[j] |
| 515 | + result_index[current_pos] = idx[j] |
| 516 | + current_pos += 1 |
| 517 | + |
| 518 | + return pandas.Series(result_data, result_index, name) |
| 519 | + |
| 520 | + return dropna_impl |
| 521 | + |
| 522 | + |
478 | 523 | def nanmean(a): |
479 | 524 | pass |
480 | 525 |
|
|
0 commit comments