Skip to content

Commit

Permalink
Merge pull request #18 from mcmcgrath13/non_tabular
Browse files Browse the repository at this point in the history
feat(non-tabular-data): return path instead of empty dataset
  • Loading branch information
davidanthoff authored Aug 2, 2019
2 parents acef41c + 01b6ed0 commit 2113fdf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ using VegaLite, VegaDatasets

dataset("iris") |> @vlplot(:point, x=:sepalLength, y=:petalWidth)
````

### Non-tabular datasets

The following datasets are not tabular in nature. A `Path` to the file location is returned instead of the data.

* earthquakes
* graticule
* londonBoroughs
* londonTubeLines
* miserables
* sf_temps
* us_10m
* world_110m
8 changes: 4 additions & 4 deletions src/VegaDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ end

function dataset(name::AbstractString)
if in(name, ["earthquakes", "graticule", "londonBoroughs", "londonTubeLines", "miserables", "sf-temps", "us-10m", "world-110m"])
@warn "Dataset not tabular: data field set to nothing, see path field for data file"
@warn "Dataset not tabular: returned Path instead of dataset"
json_filename = normpath(joinpath(@__DIR__,"..","data", "data", "$name.json"))
csv_filename = normpath(joinpath(@__DIR__,"..","data","data", "$name.csv"))
tsv_filename = normpath(joinpath(@__DIR__,"..","data","data", "$name.tsv"))
if isfile(json_filename)
return VegaDataset(nothing, Path(joinpath(@__DIR__,"..","data", "data", json_filename)))
return Path(json_filename)
elseif isfile(csv_filename)
return VegaDataset(nothing, Path(joinpath(@__DIR__,"..","data", "data", csv_filename)))
return Path(csv_filename)
elseif isfile(tsv_filename)
return VegaDataset(nothing, Path(joinpath(@__DIR__,"..","data", "data", tsv_filename)))
return Path(tsv_filename)
end
elseif isfile(joinpath(@__DIR__,"..","data", "data", name))
if splitext(name)[2]==".csv" || splitext(name)[2]==".tsv"
Expand Down
18 changes: 9 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using VegaDatasets
import IteratorInterfaceExtensions, TableTraits, TableShowUtils
import IteratorInterfaceExtensions, TableTraits, TableShowUtils, FilePaths
using Test

@testset "VegaDatasets" begin
Expand Down Expand Up @@ -61,14 +61,14 @@ miserables = dataset("miserables")
sf_temps = dataset("sf-temps")
us_10m = dataset("us-10m")
world_110m = dataset("world-110m")
@test sprint(show, earthquakes) == ""
@test sprint(show, graticule) == ""
@test sprint(show, londonBoroughs) == ""
@test sprint(show, londonTubeLines) == ""
@test sprint(show, miserables) == ""
@test sprint(show, sf_temps) == ""
@test sprint(show, us_10m) == ""
@test sprint(show, world_110m) == ""
@test typeof(earthquakes) <: FilePaths.AbstractPath
@test typeof(graticule) <: FilePaths.AbstractPath
@test typeof(londonBoroughs) <: FilePaths.AbstractPath
@test typeof(londonTubeLines) <: FilePaths.AbstractPath
@test typeof(miserables) <: FilePaths.AbstractPath
@test typeof(sf_temps) <: FilePaths.AbstractPath
@test typeof(us_10m) <: FilePaths.AbstractPath
@test typeof(world_110m) <: FilePaths.AbstractPath

end

Expand Down

0 comments on commit 2113fdf

Please sign in to comment.