Skip to content

Commit bd47245

Browse files
authored
Fix conversion of all-missing column to Pandas (#84)
1 parent c93d220 commit bd47245

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/tabletraits.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ function _construct_pandas_from_iterabletable(source)
3434
if eltype(v)<:DataValues.DataValue
3535
T = eltype(eltype(v))
3636
if T<:AbstractFloat
37+
38+
# Issue 71
39+
# If the column is all 'missing' values, we have to decide what type to give it in Pandas.
40+
# We arbitrarily default to Float64.
41+
if T == Union{}
42+
T = Float64
43+
end
44+
3745
cols[k] = T[get(i, NaN) for i in v]
3846
elseif T<:Integer
3947
cols[k] = Float64[DataValues.isna(i) ? NaN : Float64(get(i)) for i in v]

test/Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[deps]
22
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
3-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
4+
DataValues = "e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5"
45
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
56
TableTraits = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
6-
DataValues = "e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5"
77
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
8+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
89

910
[compat]
11+
DataValues = "0.4.4"
1012
IteratorInterfaceExtensions = "^0.1.1, ^1"
1113
TableTraits = "^0.4, ^1"
12-
DataValues = "0.4.4"
1314
Tables = "1"
15+
DataFrames = "1"

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Pandas
22
using Test
3+
import DataFrames
34

45
df = DataFrame(Dict(:name=>["a", "b"], :age=>[27, 30]))
56
age = values(df.age)
@@ -43,3 +44,9 @@ end
4344
# Rolling
4445
roll = rolling(Series([1,2,3,4,5]), 3)
4546
@test isequal(values(mean(roll)), [NaN, NaN, 2.0, 3.0, 4.0])
47+
48+
# Issue #71
49+
julia_df = DataFrames.DataFrame(x=[1,2], y=[missing, missing])
50+
py_df = Pandas.DataFrame(julia_df)
51+
expected_df = Pandas.DataFrame(:x=>[1,2], :y=>[NaN, NaN])
52+
@test Pandas.equals(py_df, expected_df)

0 commit comments

Comments
 (0)