@@ -833,9 +833,20 @@ def backfill_2d_inplace(algos_t[:, :] values,
833
833
834
834
835
835
# Fillna logic
836
+ # We have our own fused type since we don't need to support
837
+ # types that can't hold NAs
838
+ ctypedef fused fillna_t:
839
+ float64_t
840
+ float32_t
841
+ object
842
+ # TODO: Add datetime64 support through viewing data as uint64
843
+ uint64_t # Datetime64
844
+ # TODO: Complex support?
845
+
846
+
836
847
@ cython.boundscheck (False )
837
848
@ cython.wraparound (False )
838
- def fillna1d (ndarray arr ,
849
+ def fillna1d (fillna_t[:] arr ,
839
850
object value ,
840
851
limit = None ,
841
852
bint inf_as_na = False
@@ -856,15 +867,15 @@ def fillna1d(ndarray arr,
856
867
arr : ndarray
857
868
value : object
858
869
The value to use to replace nans
859
- limit : int , default -1
860
- The number of elements to fill. If -1 , fills all NaN values
870
+ limit : int , default None
871
+ The number of elements to fill. If None , fills all NaN values
861
872
inf_as_na:
862
873
Whether to consider INF and NEGINF as NA
863
874
"""
864
875
cdef:
865
876
Py_ssize_t i , N , lim
866
877
Py_ssize_t count = 0
867
- object val
878
+ fillna_t val
868
879
869
880
assert arr.ndim == 1, "'arr' must be 1-D."
870
881
@@ -883,7 +894,7 @@ def fillna1d(ndarray arr,
883
894
884
895
@ cython.boundscheck (False )
885
896
@ cython.wraparound (False )
886
- def fillna2d (ndarray arr ,
897
+ def fillna2d (fillna_t[:, :] arr ,
887
898
object value ,
888
899
limit = None ,
889
900
bint inf_as_na = False
@@ -904,25 +915,26 @@ def fillna2d(ndarray arr,
904
915
arr : ndarray
905
916
value : object
906
917
The value to use to replace nans
907
- limit : int , default -1
908
- The number of elements to fill. If -1 , fills all NaN values
918
+ limit : int , default None
919
+ The number of elements to fill. If None , fills all NaN values
909
920
inf_as_na:
910
921
Whether to consider INF and NEGINF as NA
911
922
"""
912
923
cdef:
913
924
Py_ssize_t i , j , n , m , lim
914
925
Py_ssize_t count = 0
915
- object val
926
+ fillna_t val
916
927
917
928
assert arr.ndim == 2, "'arr' must be 2-D."
918
929
919
930
n , m = (< object > arr).shape
920
- lim = validate_limit(n , limit)
931
+ lim = validate_limit(m , limit)
921
932
if inf_as_na:
922
933
check_func = missing.checknull_old
923
934
else:
924
935
check_func = missing.checknull
925
936
for i in range(n ):
937
+ count = 0 # Limit is per axis
926
938
for j in range (m):
927
939
val = arr[i, j]
928
940
if check_func(val) and count < lim:
0 commit comments