Skip to content

Cannot convert an object of type DataValues.DataValue{Any} to an object of type DateTime #47

Description

@IanButterworth

I'm not sure if this is a core DataValues issue or one with the implementation in ExcelFiles or DataFrames (where I posted the same issue):
queryverse/ExcelFiles.jl#13
JuliaData/DataFrames.jl#1478

(I'll close the inappropriate issues once I figure out where the issue is)

I have dataframe df where column 1 is an array of DataValues.DataValue{Any}.
How can I convert it to DateTime, and allow for missing?

This doesn’t work:

datetimes = convert(Vector{Union{DateTime,Missing}}, df[1])
MethodError: Cannot `convert` an object of type DataValues.DataValue{Any} to an object of type DateTime

Activity

  1. IanButterworth commented on Aug 11, 2018

    @IanButterworth
    Author

    Here's a concise example for testing:

    using DataFrames, Dates, ExcelFiles
    filename = "test.xlsx"
    df = DataFrame(load(filename, string("Sheet1!A1:E25"),header=true))
    df[:DateTime] = convert(Vector{Union{DateTime, Missing}},df[:DateTime])
    

    And source excel file: https://www.dropbox.com/s/cwq5m6m9179s57a/test.xlsx?dl=1

  2. IanButterworth commented on Aug 11, 2018

    @IanButterworth
    Author

    I've written a temporary function to fix the columns:

    function fixcolumn(col,T)
        arr = Vector{Union{Missing, T}}(0)
        for x in col
            try
                push!(arr,x.value)
            catch
                push!(arr,missing)
            end
        end
        return arr
    end
    

    For instance:

    df[:DateTime] = fixcolumn(df[:DateTime],DateTime)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions