|
68 | 68 | float64_t FP_ERR = 1e-13
|
69 | 69 | float64_t NaN = <float64_t>np.NaN
|
70 | 70 | int64_t NPY_NAT = get_nat()
|
| 71 | + float64_t INF = <float64_t> np.inf |
| 72 | + float64_t NEGINF = -INF |
71 | 73 |
|
72 | 74 | cdef enum TiebreakEnumType:
|
73 | 75 | TIEBREAK_AVERAGE
|
@@ -838,14 +840,15 @@ def backfill_2d_inplace(algos_t[:, :] values,
|
838 | 840 |
|
839 | 841 |
|
840 | 842 | # Fillna logic
|
841 |
| -# We have our own fused type since we don't need to support |
842 |
| -# types that can't hold NAs |
| 843 | +# We have our own fused type instead of algos_t |
| 844 | +# since we don't need to support types that can't hold NAs(ints, etc) |
843 | 845 | ctypedef fused fillna_t:
|
844 | 846 | float64_t
|
845 | 847 | float32_t
|
846 | 848 | object
|
847 |
| - # TODO: Add datetime64 support through viewing data as uint64 |
848 |
| - uint64_t # Datetime64 |
| 849 | + # TODO: Maybe add datetime64 support through viewing data as int64? |
| 850 | + # But datetime64 seems to be handled elsewhere |
| 851 | + int64_t # Datetime64 |
849 | 852 | # TODO: Complex support?
|
850 | 853 |
|
851 | 854 |
|
@@ -881,21 +884,30 @@ def fillna1d(fillna_t[:] arr,
|
881 | 884 | Py_ssize_t i, N, lim
|
882 | 885 | Py_ssize_t count=0
|
883 | 886 | fillna_t val
|
| 887 | + bint result |
884 | 888 |
|
885 | 889 | assert arr.ndim == 1, "'arr' must be 1-D."
|
886 | 890 |
|
887 | 891 | N = len(arr)
|
888 | 892 | lim = validate_limit(N, limit)
|
889 |
| - # if fillna_t == float32_t:#or fillna_t is float64_t: |
890 |
| - # check_func = util.is_nan |
| 893 | + # if inf_as_na: |
| 894 | + # check_func = checknull_old |
891 | 895 | # else:
|
892 |
| - if inf_as_na: |
893 |
| - check_func = checknull_old |
894 |
| - else: |
895 |
| - check_func = checknull |
| 896 | + # check_func = checknull |
896 | 897 | for i in range(N):
|
897 | 898 | val = arr[i]
|
898 |
| - if val != val and count < lim: |
| 899 | + if fillna_t is object: |
| 900 | + if inf_as_na: |
| 901 | + result = checknull_old(val) |
| 902 | + else: |
| 903 | + result = checknull(val) |
| 904 | + elif fillna_t is float32_t or fillna_t is float64_t: |
| 905 | + result = val != val |
| 906 | + if inf_as_na: |
| 907 | + result = result and (val == INF or val == NEGINF) |
| 908 | + else: |
| 909 | + result = val == NPY_NAT |
| 910 | + if result and count < lim: |
899 | 911 | arr[i] = value
|
900 | 912 | count+=1
|
901 | 913 | # if check_func(val) and count < lim:
|
|
0 commit comments