@@ -856,7 +856,7 @@ ctypedef fused fillna_t:
856
856
@ cython.wraparound (False )
857
857
def fillna1d (fillna_t[:] arr ,
858
858
fillna_t value ,
859
- limit = None ,
859
+ Py_ssize_t limit ,
860
860
bint inf_as_na = False
861
861
) -> ndarray:
862
862
"""
@@ -889,11 +889,6 @@ def fillna1d(fillna_t[:] arr,
889
889
assert arr.ndim == 1, "'arr' must be 1-D."
890
890
891
891
N = len (arr)
892
- lim = validate_limit(N, limit)
893
- # if inf_as_na:
894
- # check_func = checknull_old
895
- # else:
896
- # check_func = checknull
897
892
for i in range(N ):
898
893
val = arr[i]
899
894
if fillna_t is object :
@@ -907,19 +902,82 @@ def fillna1d(fillna_t[:] arr,
907
902
result = result and (val == INF or val == NEGINF)
908
903
else :
909
904
result = val == NPY_NAT
910
- if result and count < lim :
905
+ if result and count < limit :
911
906
arr[i] = value
912
907
count+= 1
913
- # if check_func(val) and count < lim:
914
- # arr[i] = value
915
- # count+=1
908
+
909
+
910
+ @ cython.boundscheck (False )
911
+ @ cython.wraparound (False )
912
+ def fillna1d_multi_values (fillna_t[:] arr ,
913
+ algos_t[:] value ,
914
+ Py_ssize_t limit ,
915
+ bint inf_as_na = False
916
+ ) -> ndarray:
917
+ """
918
+ Fills na-like elements inplace for a 1D array
919
+ according to the criteria defined in `checknull`:
920
+ - None
921
+ - nan
922
+ - NaT
923
+ - np.datetime64 representation of NaT
924
+ - np.timedelta64 representation of NaT
925
+ - NA
926
+ - Decimal("NaN")
927
+
928
+ Parameters
929
+ ----------
930
+ arr : ndarray
931
+ value : ndarray/ExtensionArray
932
+ A ndarray/ExtensionArray with same length as arr
933
+ describing which fill value to use at each position ,
934
+ with a value of np.nan indicating that a position should
935
+ not be filled
936
+ limit : int , default None
937
+ The number of elements to fill. If None , fills all NaN values
938
+ inf_as_na:
939
+ Whether to consider INF and NEGINF as NA
940
+ """
941
+ cdef:
942
+ Py_ssize_t i , N
943
+ Py_ssize_t count = 0
944
+ fillna_t val
945
+ algos_t fill_value
946
+ bint result
947
+
948
+ assert arr.ndim == 1, "'arr' must be 1-D."
949
+
950
+ N = len (arr)
951
+ for i in range(N ):
952
+ fill_value = value[i]
953
+ if fill_value != fill_value:
954
+ # np.nan don't fill
955
+ continue
956
+ val = arr[i]
957
+ if fillna_t is object :
958
+ if inf_as_na:
959
+ result = checknull_old(val)
960
+ else :
961
+ result = checknull(val)
962
+ elif fillna_t is float32_t or fillna_t is float64_t:
963
+ result = val != val
964
+ if inf_as_na:
965
+ result = result and (val == INF or val == NEGINF)
966
+ else :
967
+ result = val == NPY_NAT
968
+ if result and count < limit:
969
+ # Ugh... We have to cast here since technically could have a int64->float32
970
+ # There shouldn't be any risk here since BlockManager should check
971
+ # that the element can be held
972
+ arr[i] = < fillna_t> fill_value
973
+ count+= 1
916
974
917
975
918
976
@ cython.boundscheck (False )
919
977
@ cython.wraparound (False )
920
978
def fillna2d (fillna_t[:, :] arr ,
921
- object value ,
922
- limit = None ,
979
+ fillna_t value ,
980
+ Py_ssize_t limit ,
923
981
bint inf_as_na = False
924
982
) -> ndarray:
925
983
"""
@@ -944,14 +1002,14 @@ def fillna2d(fillna_t[:, :] arr,
944
1002
Whether to consider INF and NEGINF as NA
945
1003
"""
946
1004
cdef:
947
- Py_ssize_t i , j , n , m , lim
1005
+ Py_ssize_t i , j , n , m
948
1006
Py_ssize_t count = 0
949
1007
fillna_t val
1008
+ bint result
950
1009
951
1010
assert arr.ndim == 2, "'arr' must be 2-D."
952
1011
953
1012
n , m = (< object > arr).shape
954
- lim = validate_limit(m, limit)
955
1013
if inf_as_na:
956
1014
check_func = checknull_old
957
1015
else:
@@ -960,7 +1018,18 @@ def fillna2d(fillna_t[:, :] arr,
960
1018
count = 0 # Limit is per axis
961
1019
for j in range (m):
962
1020
val = arr[i, j]
963
- if check_func(val) and count < lim:
1021
+ if fillna_t is object :
1022
+ if inf_as_na:
1023
+ result = checknull_old(val)
1024
+ else :
1025
+ result = checknull(val)
1026
+ elif fillna_t is float32_t or fillna_t is float64_t:
1027
+ result = val != val
1028
+ if inf_as_na:
1029
+ result = result and (val == INF or val == NEGINF)
1030
+ else :
1031
+ result = val == NPY_NAT
1032
+ if result and count < limit:
964
1033
arr[i, j] = value
965
1034
count+= 1
966
1035
0 commit comments