Skip to content

Commit 17ea901

Browse files
authored
Merge pull request #63 from JuliaML/col-names
`Tables.columnnames(table)` => `Tables.columnnames(cols)`
2 parents aaefe44 + 10c4219 commit 17ea901

File tree

10 files changed

+199
-29
lines changed

10 files changed

+199
-29
lines changed

src/colspec.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ end
2424
2. use `choose(colspec, names)` function in apply:
2525
```julia
2626
function apply(transform::MyTransform, table)
27-
names = Tables.columnnames(table)
27+
cols = Tables.columns(table)
28+
names = Tables.columnnames(cols)
2829
# selected column names
2930
snames = choose(transform.colspec, names)
3031
# code...

src/transforms.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ function apply(transform::Colwise, table)
130130
end
131131

132132
# retrieve column names and values
133-
names = Tables.columnnames(table)
134133
cols = Tables.columns(table)
134+
names = Tables.columnnames(cols)
135135

136136
# function to transform a single column
137137
function colfunc(n)
@@ -159,9 +159,9 @@ function revert(transform::Colwise, newtable, cache)
159159
@assert isrevertible(transform) "transform is not revertible"
160160

161161
# transformed columns
162-
names = Tables.columnnames(newtable)
163162
cols = Tables.columns(newtable)
164-
163+
names = Tables.columnnames(cols)
164+
165165
# function to transform a single column
166166
function colfunc(i)
167167
n = names[i]
@@ -185,9 +185,9 @@ function reapply(transform::Colwise, table, cache)
185185
end
186186

187187
# retrieve column names and values
188-
names = Tables.columnnames(table)
189188
cols = Tables.columns(table)
190-
189+
names = Tables.columnnames(cols)
190+
191191
# check that cache is valid
192192
@assert length(names) == length(cache) "invalid cache for table"
193193

src/transforms/coerce.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ function apply(transform::Coerce, table)
3737
end
3838

3939
function revert(transform::Coerce, newtable, cache)
40-
names = Tables.columnnames(newtable)
4140
cols = Tables.columns(newtable)
41+
names = Tables.columnnames(cols)
42+
4243
oldcols = map(zip(cache, names)) do (T, n)
4344
x = Tables.getcolumn(cols, n)
4445
collect(T, x)
@@ -47,4 +48,3 @@ function revert(transform::Coerce, newtable, cache)
4748
𝒯 = (; zip(names, oldcols)...)
4849
𝒯 |> Tables.materializer(newtable)
4950
end
50-

src/transforms/eigenanalysis.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function apply(transform::EigenAnalysis, table)
5353
end
5454

5555
# original columns names
56-
names = Tables.columnnames(table)
56+
cols = Tables.columns(table)
57+
names = Tables.columnnames(cols)
5758

5859
# table as matrix
5960
X = Tables.matrix(table)
@@ -77,7 +78,8 @@ end
7778

7879
function revert(::EigenAnalysis, newtable, cache)
7980
# transformed column names
80-
names = Tables.columnnames(newtable)
81+
cols = Tables.columns(newtable)
82+
names = Tables.columnnames(cols)
8183

8284
# table as matrix
8385
Z = Tables.matrix(newtable)
@@ -103,7 +105,8 @@ function reapply(transform::EigenAnalysis, table, cache)
103105
end
104106

105107
# original columns names
106-
names = Tables.columnnames(table)
108+
cols = Tables.columns(table)
109+
names = Tables.columnnames(cols)
107110

108111
# table as matrix
109112
X = Tables.matrix(table)

src/transforms/filter.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,17 @@ _nonmissing(::Type{Union{Missing,T}}, x) where {T} = collect(T, x)
102102
_nonmissing(x) = _nonmissing(eltype(x), x)
103103

104104
function apply(transform::DropMissing, table)
105-
names = Tables.columnnames(table)
105+
cols = Tables.columns(table)
106+
names = Tables.columnnames(cols)
106107
types = Tables.schema(table).types
107108
snames = choose(transform.colspec, names)
108109
ftrans = _ftrans(transform, snames)
109110
newtable, fcache = apply(ftrans, table)
110111

111112
# post-processing
112-
cols = Tables.columns(newtable)
113+
ncols = Tables.columns(newtable)
113114
pcols = map(names) do n
114-
x = Tables.getcolumn(cols, n)
115+
x = Tables.getcolumn(ncols, n)
115116
n snames ? _nonmissing(x) : x
116117
end
117118
𝒯 = (; zip(names, pcols)...)
@@ -125,7 +126,7 @@ function revert(::DropMissing, newtable, cache)
125126

126127
# pre-processing
127128
cols = Tables.columns(newtable)
128-
names = Tables.columnnames(newtable)
129+
names = Tables.columnnames(cols)
129130
pcols = map(zip(types, names)) do (T, n)
130131
x = Tables.getcolumn(cols, n)
131132
collect(T, x)

src/transforms/functional.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ _functuple(func::NamedTuple, names) = func
5959

6060
function apply(transform::Functional, table)
6161
cols = Tables.columns(table)
62-
names = Tables.columnnames(table)
62+
names = Tables.columnnames(cols)
6363
funcs = _functuple(transform.func, names)
6464

6565
ncols = map(names) do nm
@@ -77,7 +77,7 @@ function revert(transform::Functional, newtable, cache)
7777
@assert isrevertible(transform) "Transform is not revertible."
7878

7979
cols = Tables.columns(newtable)
80-
names = Tables.columnnames(newtable)
80+
names = Tables.columnnames(cols)
8181
funcs = _functuple(transform.func, names)
8282

8383
ocols = map(names) do nm

src/transforms/parallel.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function apply(p::Parallel, table)
3333
newtable = tablehcat(tables)
3434

3535
# save original column names
36-
onames = Tables.columnnames(table)
36+
ocols = Tables.columns(table)
37+
onames = Tables.columnnames(ocols)
3738

3839
# find first revertible transform
3940
ind = findfirst(isrevertible, p.transforms)
@@ -42,7 +43,8 @@ function apply(p::Parallel, table)
4243
rinfo = if isnothing(ind)
4344
nothing
4445
else
45-
tnames = Tables.columnnames.(tables)
46+
tcols = Tables.columns.(tables)
47+
tnames = Tables.columnnames.(tcols)
4648
ncols = length.(tnames)
4749
nrcols = ncols[ind]
4850
start = sum(ncols[1:ind-1]) + 1
@@ -99,7 +101,7 @@ function tablehcat(tables)
99101
varsdict = Set{Symbol}()
100102
for 𝒯 in tables
101103
cols = Tables.columns(𝒯)
102-
vars = Tables.columnnames(𝒯)
104+
vars = Tables.columnnames(cols)
103105
vals = [Tables.getcolumn(cols, var) for var in vars]
104106
for (var, val) in zip(vars, vals)
105107
while var varsdict

src/transforms/rename.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ end
3535

3636

3737
function _rename(names, table)
38-
oldnames = Tables.columnnames(table)
38+
cols = Tables.columns(table)
39+
oldnames = Tables.columnnames(cols)
3940

4041
# check if requested renames exist in the table
4142
@assert keys(names) oldnames "invalid column names"
@@ -46,7 +47,6 @@ function _rename(names, table)
4647
end
4748

4849
# table with new tables
49-
cols = Tables.columns(table)
5050
vals = [Tables.getcolumn(cols, name) for name in oldnames]
5151
𝒯 = (; zip(newnames, vals)...) |> Tables.materializer(table)
5252

src/transforms/select.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ Select(cols::T...) where {T<:ColSelector} =
8080
isrevertible(::Type{<:Select}) = true
8181

8282
function apply(transform::Select, table)
83+
# original columns
84+
cols = Tables.columns(table)
85+
8386
# retrieve relevant column names
84-
allcols = collect(Tables.columnnames(table))
87+
allcols = collect(Tables.columnnames(cols))
8588
select = choose(transform.colspec, allcols)
8689
reject = setdiff(allcols, select)
8790

@@ -95,9 +98,6 @@ function apply(transform::Select, table)
9598
reject = reject[sorted]
9699
rinds = rinds[sorted]
97100

98-
# original columns
99-
cols = Tables.columns(table)
100-
101101
# rejected columns
102102
rcols = [Tables.getcolumn(cols, name) for name in reject]
103103

@@ -107,7 +107,7 @@ end
107107
function revert(::Select, newtable, cache)
108108
# selected columns
109109
cols = Tables.columns(newtable)
110-
select = Tables.columnnames(newtable)
110+
select = Tables.columnnames(cols)
111111
scols = [Tables.getcolumn(cols, name) for name in select]
112112

113113
# rejected columns
@@ -162,7 +162,8 @@ Reject(cols::T...) where {T<:ColSelector} =
162162
isrevertible(::Type{<:Reject}) = true
163163

164164
function apply(transform::Reject, table)
165-
allcols = Tables.columnnames(table)
165+
cols = Tables.columns(table)
166+
allcols = Tables.columnnames(cols)
166167
reject = choose(transform.colspec, allcols)
167168
select = setdiff(allcols, reject)
168169
strans = Select(select)

0 commit comments

Comments
 (0)