Skip to content

Commit ecd2fec

Browse files
author
Christopher Doris
committed
convert nan to missing
1 parent 86a6946 commit ecd2fec

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/pywrap/PyPandasDataFrame.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,16 @@ function Base.getindex(df::PyPandasDataFrame, k::String)
6666
ans = pyconvert_and_del(AbstractVector{df.columntypes[k]}, c)
6767
else
6868
ans = pyconvert_and_del(AbstractVector, c)
69+
# narrow the type
70+
ans = identity.(ans)
6971
# convert any Py to something more useful
7072
if Py <: eltype(ans)
7173
ans = [x isa Py ? pyconvert(Any, x) : x for x in ans]
7274
end
75+
# convert NaN to missing
76+
if eltype(ans) != Float64 && Float64 <: eltype(ans)
77+
ans = [x isa Float64 && isnan(x) ? missing : x for x in ans]
78+
end
7379
end
7480
return ans :: AbstractVector
7581
end

0 commit comments

Comments
 (0)