diff --git a/Project.toml b/Project.toml index 20ff239..276ee30 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "1.5.0" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" DataValues = "e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -22,5 +23,5 @@ Lazy = "0.15" PyCall = "1.90" TableTraits = "^0.4, ^1" TableTraitsUtils = "^0.3, ^0.4, ^1" -julia = "0.7, 1" Tables = "1" +julia = "0.7, 1" diff --git a/src/Pandas.jl b/src/Pandas.jl index b06f154..b8e1c85 100644 --- a/src/Pandas.jl +++ b/src/Pandas.jl @@ -1,6 +1,7 @@ __precompile__(true) module Pandas +using Dates using PyCall using Lazy using Compat @@ -76,9 +77,27 @@ end quot(x) = Expr(:quote, x) + +function convert_datetime_series_to_julia_vector(series) + N = length(series) + out = Array{Dates.DateTime}(undef, N) + for i in 1:N + # PyCall.jl overloads the getindex method on `series` to automatically convert + # to a Julia date type. + out[i] = series[i] + end + return out +end + + function Base.Array(x::PandasWrapped) + if typeof(x) <: Series && x.pyo.dtype == np.dtype("["a", "b"], :age=>[27, 30])) age = values(df.age) @@ -50,3 +52,19 @@ 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]) @test Pandas.equals(py_df, expected_df) + +# Issue #68 +py""" +import pandas as pd + +def get_df(): + df = pd.DataFrame({ + "a":pd.to_datetime(["2021.01.15","2021.01.15","2020.04.06"]) + }) + return df +""" + +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)]