Skip to content

Commit b94e650

Browse files
authored
Merge pull request #12 from JuliaData/jq/tables1
Add support for Tables.jl 1.0
2 parents 1b8414c + ae2d70f commit b94e650

File tree

5 files changed

+32
-53
lines changed

5 files changed

+32
-53
lines changed

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,29 @@ sudo: false
55
os:
66
- linux
77
- osx
8+
- windows
9+
10+
arch:
11+
- x64
12+
- x86
813

914
julia:
1015
- 1.0
11-
- 1.1
16+
- 1.3
1217
- nightly
1318

1419
env:
1520
- JULIA_PROJECT="@."
1621

1722
matrix:
23+
exclude:
24+
- os: osx
25+
arch: x86
1826
allow_failures:
1927
- julia: nightly
2028

2129
notifications:
2230
email: false
2331

2432
after_success:
25-
- julia -e 'ENV["TRAVIS_JULIA_VERSION"] != "1.1" && ENV["TRAVIS_OS_NAME"] != "linux" && exit(); using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
26-
33+
- julia -e 'ENV["TRAVIS_JULIA_VERSION"] == "1.3" && ENV["TRAVIS_OS_NAME"] != "linux" && exit(); using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name = "JSONTables"
22
uuid = "b9914132-a727-11e9-1322-f18e41205b0b"
33
authors = ["Jacob Quinn <quinn.jacobd@gmail.com>"]
4-
version = "0.1.3"
4+
version = "1.0.0"
55

66
[deps]
77
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
8+
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
89
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
910

1011
[compat]
11-
JSON3 = "0.1"
12-
Tables = "0.2"
12+
JSON3 = "1"
13+
StructTypes = "1"
14+
Tables = "1"
1315
julia = "1"
1416

1517
[extras]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# JSONTables.jl
22

3-
A package that provides a JSON integration with the [Tables.jl](https://github.com/JuliaData/Tables.jl) interface, that is, it provides the `jsontable` function as a way to treat a JSON object of arrays, or a JSON array of objects, as a Tables.jl-compatible source. This allows, among other things, loading JSON "tabular" data into a DataFrame, or a JuliaDB table, or written out directly as a csv file.
3+
A package that provides a JSON integration with the [Tables.jl](https://github.com/JuliaData/Tables.jl) interface, that is, it provides the `jsontable` function as a way to treat a JSON object of arrays, or a JSON array of objects, as a Tables.jl-compatible source. This allows, among other things, loading JSON "tabular" data into a `DataFrame`, or a JuliaDB.jl table, or written out directly as a csv file.
44

5-
JSONTables.jl also provides two "write" functions, `objecttable` and `arraytable`, for taking any Tables.jl-comptabile source (e.g. DataFrame, ODBC.Query, etc.) and writing the table out either as a JSON object of arrays, or array of objects, respectively.
5+
JSONTables.jl also provides two "write" functions, `objecttable` and `arraytable`, for taking any Tables.jl-comptabile source (e.g. `DataFrame`, `CSV.File`, etc.) and writing the table out either as a JSON object of arrays, or array of objects, respectively.
66

77
So in short:
88
```julia

appveyor.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/JSONTables.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module JSONTables
22

3-
using JSON3, Tables
3+
using StructTypes, JSON3, Tables
44

55
export jsontable, arraytable, objecttable
66

@@ -42,6 +42,10 @@ Base.copy(x::MissingVector) = map(y->y isa JSON3.Object || y isa JSON3.Array ? c
4242
Base.propertynames(x::Table{true}) = Tuple(keys(getfield(x, :source)))
4343
Base.getproperty(x::Table{true}, nm::Symbol) = MissingVector(getproperty(getfield(x, :source), nm))
4444

45+
Tables.columnnames(x::Table{true}) = propertynames(x)
46+
Tables.getcolumn(x::Table{true}, i::Int) = getproperty(x, propertynames(x)[i])
47+
Tables.getcolumn(x::Table{true}, nm::Symbol) = getproperty(x, nm)
48+
4549
# row source
4650
Tables.rowaccess(::Type{Table{false, T}}) where {T} = true
4751
Tables.rows(x::Table{false}) = x
@@ -51,11 +55,13 @@ Base.length(x::Table{false}) = length(x.source)
5155
Base.IteratorEltype(::Type{Table{false, T}}) where {T} = Base.HasEltype()
5256
Base.eltype(x::Table{false, JSON3.Array{T}}) where {T} = T
5357

54-
struct MissingRow{T}
58+
struct MissingRow{T} <: Tables.AbstractRow
5559
x::T
5660
end
57-
Base.propertynames(x::MissingRow) = propertynames(getfield(x, :x))
58-
Base.getproperty(x::MissingRow, nm::Symbol) = miss(getproperty(getfield(x, :x), nm))
61+
62+
Tables.columnnames(x::MissingRow) = propertynames(getfield(x, :x))
63+
Tables.getcolumn(x::MissingRow, nm::Symbol) = miss(getproperty(getfield(x, :x), nm))
64+
Tables.getcolumn(x::MissingRow, i::Int) = getproperty(x, propertynames(x)[i])
5965

6066
@inline function Base.iterate(x::Table{false})
6167
st = iterate(x.source)
@@ -76,21 +82,21 @@ struct ObjectTable{T}
7682
x::T
7783
end
7884

79-
JSON3.StructType(::Type{<:ObjectTable}) = JSON3.ObjectType()
80-
Base.pairs(x::ObjectTable) = zip(propertynames(x.x), Tables.eachcolumn(x.x))
85+
StructTypes.StructType(::Type{<:ObjectTable}) = StructTypes.DictType()
86+
Base.pairs(x::ObjectTable) = zip(Tables.columnnames(x.x), Tables.Columns(x.x))
8187

8288
struct ArrayTable{T}
8389
x::T
8490
end
8591

86-
JSON3.StructType(::Type{<:ArrayTable}) = JSON3.ArrayType()
92+
StructTypes.StructType(::Type{<:ArrayTable}) = StructTypes.ArrayType()
8793

8894
struct ArrayRow{T}
8995
x::T
9096
end
9197

92-
JSON3.StructType(::Type{<:ArrayRow}) = JSON3.ObjectType()
93-
Base.pairs(x::ArrayRow) = zip(propertynames(x.x), Tables.eachcolumn(x.x))
98+
StructTypes.StructType(::Type{<:ArrayRow}) = StructTypes.DictType()
99+
Base.pairs(x::ArrayRow) = zip(Tables.columnnames(x.x), Tables.Columns(x.x))
94100

95101
Base.IteratorSize(::Type{ArrayTable{T}}) where {T} = IteratorSize(T)
96102
Base.length(x::ArrayTable) = length(x.x)

0 commit comments

Comments
 (0)