Skip to content

Commit 2d21824

Browse files
author
Christopher Doris
committed
simpler column conversion (now copies)
1 parent de39c72 commit 2d21824

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/pywrap/PyPandasDataFrame.jl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,12 @@ function _columns(df, columnnames, columntypes)
8181
else
8282
column = pyconvert(AbstractVector, pycolumn)
8383
if eltype(column) == Py
84-
# guess a column type based on the types of the elements
85-
ts = pybuiltins.set(pybuiltins.map(pybuiltins.type, pycolumn))
86-
Ts = Type[pyconvert_preferred_type(t) for t in ts]
87-
T = isempty(Ts) ? Any : reduce(promote_type, Ts)
88-
column = pyconvert(AbstractVector{T}, pycolumn)
89-
# if all items are either NaN or not Float64, convert NaN to missing
90-
if T != Float64 && Float64 in Ts && !any(x isa Float64 && !isnan(x) for x in column)
91-
Ts = Type[T for T in Ts if T != Float64]
92-
push!(Ts, Missing)
93-
T = reduce(promote_type, Ts)
94-
column = pyconvert(AbstractVector{T}, pycolumn)
84+
column = pyconvert(AbstractVector{Any}, pycolumn)
85+
end
86+
if !isconcretetype(eltype(column))
87+
column = [(x === nothing) ? missing : x for x in column]
88+
if eltype(column) != Float64 && Float64 <: eltype(column)
89+
column = [x === NaN ? missing : x for x in column]
9590
end
9691
end
9792
end
@@ -102,5 +97,6 @@ function _columns(df, columnnames, columntypes)
10297
# TODO: realising columns to vectors could be done lazily with a different table type
10398
schema = Tables.Schema(colnames, coltypes)
10499
coldict = Tables.OrderedDict(k=>v for (k,v) in zip(colnames, columns))
105-
Tables.DictColumnTable(schema, coldict)
100+
table = Tables.DictColumnTable(schema, coldict)
101+
Tables.columns(table)
106102
end

0 commit comments

Comments
 (0)