Hi,
I’m trying to understand how to design interfaces for types in Julia well.
More specifically, I am writing a type which is effectively a wrapper around a DataFrame.
Its purpose is to manage some configuration for an application.
Initially, I thought it should be constructable from a String, that String being the name of a file from which to read data. (Not the data itself.)
I then realized this was probably designing at the wrong level of abstraction.
A DataFrame is not constructable from a filename. (A String containing the name of a file.)
Instead, at least in the case of reading from CSV, it is constructable from a CSV File object.
julia> typeof(CSV.File("example.csv"))
CSVFile
You then use that to build a DataFrame like so.
julia> DataFrame(CSV.File("example.csv"))
DataFrame...
It would probably make a lot of sense to do something similar to what DataFrames
does. So I tried to inspect what types are used in the constructor functions.
julia> methods(DataFrame())
... some stuff ... nothing obviously relevant to CSVFile ...
From this I was hoping to figure out what type is used to build a constructor function which can create a DataFrame
object from a CSVFile
object.
Of course, DataFrames can be constructed from other types of file encoding, not just CSV. So it should be something generic.
julia> supertype(CSV.File)
AbstractVector{Row}
The above provides a hint. A DataFrame is constructable from an AbstractVector, and a CSVFile is an AbstractVector.
But what is Row
here, or how can I inspect it to find out more information?