Skip to content

Commit

Permalink
Switch to OrderedDict for import (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: Páll Haraldsson <[email protected]>

Co-authored-by: Jonathan Malmaud <[email protected]>
  • Loading branch information
PallHaraldsson and malmaud authored Aug 28, 2021
1 parent bf5ddfd commit 97c4602
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DataValues = "e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -25,3 +26,4 @@ TableTraits = "^0.4, ^1"
TableTraitsUtils = "^0.3, ^0.4, ^1"
Tables = "1"
julia = "0.7, 1"
OrderedCollections = "1"
3 changes: 2 additions & 1 deletion src/tabletraits.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using IteratorInterfaceExtensions
using TableTraitsUtils
using OrderedCollections: OrderedDict
import DataValues

IteratorInterfaceExtensions.isiterable(x::DataFrame) = true
Expand Down Expand Up @@ -28,7 +29,7 @@ function _construct_pandas_from_iterabletable(source)
y = create_columns_from_iterabletable(source, errorhandling=:returnvalue)
y===nothing && return nothing
columns, column_names = y[1], y[2]
cols = Dict{Symbol,Any}(i[1]=>i[2] for i in zip(column_names, columns))
cols = OrderedDict{Symbol,Any}(i[1]=>i[2] for i in zip(column_names, columns))

for (k,v) in pairs(cols)
if eltype(v)<:DataValues.DataValue
Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ roll = rolling(Series([1,2,3,4,5]), 3)
# Issue #71
julia_df = DataFrames.DataFrame(x=[1,2], y=[missing, missing])
py_df = Pandas.DataFrame(julia_df)
expected_df = Pandas.DataFrame(:x=>[1,2], :y=>[NaN, NaN])
expected_df = Pandas.DataFrame(:x=>[1,2], :y=>[NaN, NaN])[["x", "y"]]
@test Pandas.equals(py_df, expected_df)

# Issue #68
Expand All @@ -68,3 +68,8 @@ py_df = py"get_df"()|>Pandas.DataFrame
julia_df = DataFrames.DataFrame(py_df)

@test julia_df.a == [DateTime(2021, 1, 15), DateTime(2021, 1, 15), DateTime(2020, 4, 6)]

# Issue #72
julia_df= DataFrames.DataFrame(C = 1:4, A = 5:8, B = 9:12)
py_df = Pandas.DataFrame(julia_df)
@test all(Pandas.columns(py_df) .== ["C","A","B"])

0 comments on commit 97c4602

Please sign in to comment.