Skip to content

Commit 21fcbd2

Browse files
committed
More support
1 parent 18eee84 commit 21fcbd2

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

pandas/_libs/algos.pyx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ cdef:
6868
float64_t FP_ERR = 1e-13
6969
float64_t NaN = <float64_t>np.NaN
7070
int64_t NPY_NAT = get_nat()
71+
float64_t INF = <float64_t> np.inf
72+
float64_t NEGINF = -INF
7173

7274
cdef enum TiebreakEnumType:
7375
TIEBREAK_AVERAGE
@@ -838,14 +840,15 @@ def backfill_2d_inplace(algos_t[:, :] values,
838840

839841

840842
# 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)
843845
ctypedef fused fillna_t:
844846
float64_t
845847
float32_t
846848
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
849852
# TODO: Complex support?
850853

851854

@@ -881,21 +884,30 @@ def fillna1d(fillna_t[:] arr,
881884
Py_ssize_t i, N, lim
882885
Py_ssize_t count=0
883886
fillna_t val
887+
bint result
884888

885889
assert arr.ndim == 1, "'arr' must be 1-D."
886890

887891
N = len(arr)
888892
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
891895
# else:
892-
if inf_as_na:
893-
check_func = checknull_old
894-
else:
895-
check_func = checknull
896+
# check_func = checknull
896897
for i in range(N):
897898
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:
899911
arr[i] = value
900912
count+=1
901913
# if check_func(val) and count < lim:

pandas/core/internals/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def fillna(
462462
downcast=None,
463463
)
464464
else:
465-
# TODO: Verify that this works for EAs
465+
# TODO: This seems to work for EAS, verify it does
466466
return [
467467
self.make_block_same_class(
468468
values=self.values.fillna(value=value, limit=limit)

0 commit comments

Comments
 (0)