Skip to content

Commit 19821b9

Browse files
andreasnoackararslan
authored andcommitted
Preparation for Julia 0.6 (#1164)
* Change sub to view since sub is now removed from Base. Don't import head and tail from DataArrays since they are no longer defined there. * Fix deprecated syntax * Drop Juno dependency * Don't require require that the DataFrame wraps a Vector{Any} * Fix ambiguity in hcat * Use Milan's reserved words fix from DataTables * Minor cleanup * Remove unnecessary compats, add necessary ones
1 parent baa33d9 commit 19821b9

31 files changed

+208
-251
lines changed

Diff for: .travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
language: julia
33
julia:
4-
- 0.4
54
- 0.5
65
- nightly
76
os:
@@ -17,4 +16,3 @@ script:
1716
after_success:
1817
- julia -e 'cd(Pkg.dir("DataFrames")); Pkg.add("Documenter"); Pkg.add("Query"); include(joinpath("docs", "make.jl"))'
1918
- julia -e 'cd(Pkg.dir("DataFrames")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
20-

Diff for: REQUIRE

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
julia 0.4
1+
julia 0.5
22
DataArrays 0.3.4
33
StatsBase 0.11.0
44
GZip
55
SortingAlgorithms
66
Reexport
7-
Compat 0.8.4
7+
Compat 0.18.0
88
FileIO 0.1.2
9-
Juno 0.2.4

Diff for: appveyor.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
environment:
22
matrix:
3-
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
4-
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
53
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
64
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
75
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"

Diff for: docs/src/lib/utilities.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Pages = ["utilities.md"]
1010
```
1111

1212
...
13-
13+
1414
```@docs
1515
eltypes
1616
head
17-
complete_cases
18-
complete_cases!
17+
completecases
18+
completecases!
1919
describe
2020
dump
2121
names!
@@ -26,5 +26,3 @@ tail
2626
unique
2727
unique!
2828
```
29-
30-

Diff for: src/DataFrames.jl

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION >= v"0.4.0-dev+6521" && __precompile__(true)
1+
__precompile__()
22

33
module DataFrames
44

@@ -9,7 +9,6 @@ module DataFrames
99
##############################################################################
1010

1111
using Compat
12-
import Compat.String
1312
using Reexport
1413
@reexport using StatsBase
1514
@reexport using DataArrays
@@ -54,15 +53,16 @@ export @~,
5453
coefnames,
5554
colwise,
5655
combine,
57-
complete_cases,
58-
complete_cases!,
56+
completecases,
57+
completecases!,
5958
setcontrasts!,
6059
deleterows!,
6160
describe,
6261
eachcol,
6362
eachrow,
6463
eltypes,
6564
groupby,
65+
head,
6666
melt,
6767
meltdf,
6868
names!,
@@ -80,6 +80,7 @@ export @~,
8080
showcols,
8181
stack,
8282
stackdf,
83+
tail,
8384
unique!,
8485
unstack,
8586
writetable,
@@ -93,12 +94,6 @@ export @~,
9394
##
9495
##############################################################################
9596

96-
if VERSION < v"0.5.0-dev+2023"
97-
_displaysize(x...) = Base.tty_size()
98-
else
99-
const _displaysize = Base.displaysize
100-
end
101-
10297
for (dir, filename) in [
10398
("other", "utils.jl"),
10499
("other", "index.jl"),

Diff for: src/abstractdataframe/abstractdataframe.jl

+30-28
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ The following are normally implemented for AbstractDataFrames:
2525
* [`tail`]({ref}) : last `n` rows
2626
* `convert` : convert to an array
2727
* `DataArray` : convert to a DataArray
28-
* [`complete_cases`]({ref}) : indexes of complete cases (rows with no NA's)
29-
* [`complete_cases!`]({ref}) : remove rows with NA's
28+
* [`completecases`]({ref}) : indexes of complete cases (rows with no NA's)
29+
* [`completecases!`]({ref}) : remove rows with NA's
3030
* [`nonunique`]({ref}) : indexes of duplicate rows
3131
* [`unique!`]({ref}) : remove duplicate rows
3232
* `similar` : a DataFrame with similar columns as `d`
@@ -59,7 +59,7 @@ d[[1:3; 5], :]
5959
6060
`setindex` works similarly.
6161
"""
62-
abstract AbstractDataFrame
62+
@compat abstract type AbstractDataFrame end
6363

6464
##############################################################################
6565
##
@@ -165,10 +165,10 @@ rename(f::Function, df::AbstractDataFrame)
165165
166166
```julia
167167
df = DataFrame(i = 1:10, x = rand(10), y = rand(["a", "b", "c"], 10))
168-
rename(x -> @compat(Symbol)(uppercase(string(x))), df)
169-
rename(df, @compat(Dict(:i=>:A, :x=>:X)))
168+
rename(x -> Symbol(uppercase(string(x))), df)
169+
rename(df, Dict(:i=>:A, :x=>:X))
170170
rename(df, :y, :Y)
171-
rename!(df, @compat(Dict(:i=>:A, :x=>:X)))
171+
rename!(df, Dict(:i=>:A, :x=>:X))
172172
```
173173
174174
"""
@@ -199,7 +199,7 @@ eltypes(df)
199199
"""
200200
function eltypes(df::AbstractDataFrame)
201201
ncols = size(df, 2)
202-
res = Array(Type, ncols)
202+
res = Vector{Type}(ncols)
203203
for j in 1:ncols
204204
res[j] = eltype(df[j])
205205
end
@@ -231,10 +231,10 @@ Base.ndims(::AbstractDataFrame) = 2
231231
Base.similar(df::AbstractDataFrame, dims::Int) =
232232
DataFrame(Any[similar(x, dims) for x in columns(df)], copy(index(df)))
233233

234-
nas{T}(dv::AbstractArray{T}, dims::@compat(Union{Int, Tuple{Vararg{Int}}})) = # TODO move to datavector.jl?
235-
DataArray(Array(T, dims), trues(dims))
234+
nas{T}(dv::AbstractArray{T}, dims::Union{Int, Tuple{Vararg{Int}}}) = # TODO move to datavector.jl?
235+
DataArray(Array{T}(dims), trues(dims))
236236

237-
nas{T,R}(dv::PooledDataArray{T,R}, dims::@compat(Union{Int, Tuple{Vararg{Int}}})) =
237+
nas{T,R}(dv::PooledDataArray{T,R}, dims::Union{Int, Tuple{Vararg{Int}}}) =
238238
PooledDataArray(DataArrays.RefArray(zeros(R, dims)), dv.pool)
239239

240240
nas(df::AbstractDataFrame, dims::Int) =
@@ -285,10 +285,10 @@ Base.isempty(df::AbstractDataFrame) = ncol(df) == 0
285285
##
286286
##############################################################################
287287

288-
DataArrays.head(df::AbstractDataFrame, r::Int) = df[1:min(r,nrow(df)), :]
289-
DataArrays.head(df::AbstractDataFrame) = head(df, 6)
290-
DataArrays.tail(df::AbstractDataFrame, r::Int) = df[max(1,nrow(df)-r+1):nrow(df), :]
291-
DataArrays.tail(df::AbstractDataFrame) = tail(df, 6)
288+
head(df::AbstractDataFrame, r::Int) = df[1:min(r,nrow(df)), :]
289+
head(df::AbstractDataFrame) = head(df, 6)
290+
tail(df::AbstractDataFrame, r::Int) = df[max(1,nrow(df)-r+1):nrow(df), :]
291+
tail(df::AbstractDataFrame) = tail(df, 6)
292292

293293
"""
294294
Show the first or last part of an AbstractDataFrame
@@ -443,7 +443,7 @@ end
443443
Indexes of complete cases (rows without NA's)
444444
445445
```julia
446-
complete_cases(df::AbstractDataFrame)
446+
completecases(df::AbstractDataFrame)
447447
```
448448
449449
**Arguments**
@@ -454,23 +454,23 @@ complete_cases(df::AbstractDataFrame)
454454
455455
* `::Vector{Bool}` : indexes of complete cases
456456
457-
See also [`complete_cases!`]({ref}).
457+
See also [`completecases!`]({ref}).
458458
459459
**Examples**
460460
461461
```julia
462462
df = DataFrame(i = 1:10, x = rand(10), y = rand(["a", "b", "c"], 10))
463463
df[[1,4,5], :x] = NA
464464
df[[9,10], :y] = NA
465-
complete_cases(df)
465+
completecases(df)
466466
```
467467
468468
"""
469-
function complete_cases(df::AbstractDataFrame)
469+
function completecases(df::AbstractDataFrame)
470470
## Returns a Vector{Bool} of indexes of complete cases (rows with no NA's).
471-
res = !isna(df[1])
471+
res = (!).(isna(df[1]))
472472
for i in 2:ncol(df)
473-
res &= !isna(df[i])
473+
res .&= (!).(isna(df[i]))
474474
end
475475
res
476476
end
@@ -479,7 +479,7 @@ end
479479
Delete rows with NA's.
480480
481481
```julia
482-
complete_cases!(df::AbstractDataFrame)
482+
completecases!(df::AbstractDataFrame)
483483
```
484484
485485
**Arguments**
@@ -490,19 +490,19 @@ complete_cases!(df::AbstractDataFrame)
490490
491491
* `::AbstractDataFrame` : the updated version
492492
493-
See also [`complete_cases`]({ref}).
493+
See also [`completecases`]({ref}).
494494
495495
**Examples**
496496
497497
```julia
498498
df = DataFrame(i = 1:10, x = rand(10), y = rand(["a", "b", "c"], 10))
499499
df[[1,4,5], :x] = NA
500500
df[[9,10], :y] = NA
501-
complete_cases!(df)
501+
completecases!(df)
502502
```
503503
504504
"""
505-
complete_cases!(df::AbstractDataFrame) = deleterows!(df, find(!complete_cases(df)))
505+
completecases!(df::AbstractDataFrame) = deleterows!(df, find(!, completecases(df)))
506506

507507
function Base.convert(::Type{Array}, df::AbstractDataFrame)
508508
convert(Matrix, df)
@@ -516,7 +516,7 @@ function Base.convert{T}(::Type{Array{T}}, df::AbstractDataFrame)
516516
end
517517
function Base.convert{T}(::Type{Matrix{T}}, df::AbstractDataFrame)
518518
n, p = size(df)
519-
res = Array(T, n, p)
519+
res = Matrix{T}(n, p)
520520
idx = 1
521521
for col in columns(df)
522522
anyna(col) && error("DataFrame contains NAs")
@@ -598,8 +598,8 @@ unique!(df::AbstractDataFrame) = deleterows!(df, find(nonunique(df)))
598598
unique!(df::AbstractDataFrame, cols::Any) = deleterows!(df, find(nonunique(df, cols)))
599599

600600
# Unique rows of an AbstractDataFrame.
601-
Base.unique(df::AbstractDataFrame) = df[!nonunique(df), :]
602-
Base.unique(df::AbstractDataFrame, cols::Any) = df[!nonunique(df, cols), :]
601+
Base.unique(df::AbstractDataFrame) = df[(!).(nonunique(df)), :]
602+
Base.unique(df::AbstractDataFrame, cols::Any) = df[(!).(nonunique(df, cols)), :]
603603

604604
"""
605605
Delete duplicate rows
@@ -680,8 +680,10 @@ without(df::AbstractDataFrame, c::Any) = without(df, index(df)[c])
680680

681681
# catch-all to cover cases where indexing returns a DataFrame and copy doesn't
682682
Base.hcat(df::AbstractDataFrame, x) = hcat!(df[:, :], x)
683+
Base.hcat(df1::AbstractDataFrame, df2::AbstractDataFrame) = hcat!(df[:, :], df2)
683684

684685
Base.hcat(df::AbstractDataFrame, x, y...) = hcat!(hcat(df, x), y...)
686+
Base.hcat(df1::AbstractDataFrame, df2::AbstractDataFrame, dfn::AbstractDataFrame...) = hcat!(hcat(df1, df2), dfn...)
685687

686688
# vcat only accepts DataFrames. Finds union of columns, maintaining order
687689
# of first df. Missing data becomes NAs.
@@ -770,7 +772,7 @@ function Base.hash(df::AbstractDataFrame)
770772
for i in 1:size(df, 2)
771773
h = hash(df[i], h)
772774
end
773-
return @compat UInt(h)
775+
return UInt(h)
774776
end
775777

776778

Diff for: src/abstractdataframe/io.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ function printtable(io::IO,
4444
for j in 1:p
4545
if ! (isna(df[j],i))
4646
if ! (etypes[j] <: Real)
47-
print(io, quotemark)
48-
escapedprint(io, df[i, j], quotestr)
49-
print(io, quotemark)
47+
print(io, quotemark)
48+
escapedprint(io, df[i, j], quotestr)
49+
print(io, quotemark)
5050
else
51-
print(io, df[i, j])
51+
print(io, df[i, j])
5252
end
5353
else
54-
print(io, nastring)
54+
print(io, nastring)
5555
end
5656
if j < p
57-
print(io, separator)
57+
print(io, separator)
5858
else
5959
print(io, '\n')
6060
end
@@ -133,7 +133,7 @@ function writetable(filename::AbstractString,
133133
# When 'append'-ing to a nonempty file,
134134
# 'header' triggers a check for matching colnames
135135
if header
136-
if any(i -> @compat(Symbol(file_df[1, i])) != index(df)[i], 1:size(df, 2))
136+
if any(i -> Symbol(file_df[1, i]) != index(df)[i], 1:size(df, 2))
137137
throw(KeyError("Column names don't match names in file"))
138138
end
139139

@@ -181,7 +181,7 @@ end
181181
write(io, "</tr>")
182182
write(io, "</thead>")
183183
write(io, "<tbody>")
184-
tty_rows, tty_cols = _displaysize(io)
184+
tty_rows, tty_cols = displaysize(io)
185185
mxrow = min(n,tty_rows)
186186
for row in 1:mxrow
187187
write(io, "<tr>")

Diff for: src/abstractdataframe/join.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ function join_idx(left, right, max_groups)
3535
left_pos = 0
3636
right_pos = 0
3737

38-
left_indexer = Array(Int, tcount)
39-
right_indexer = Array(Int, tcount)
40-
leftonly_indexer = Array(Int, lcount)
41-
rightonly_indexer = Array(Int, rcount)
38+
left_indexer = Vector{Int}(tcount)
39+
right_indexer = Vector{Int}(tcount)
40+
leftonly_indexer = Vector{Int}(lcount)
41+
rightonly_indexer = Vector{Int}(rcount)
4242
for i in 1:(max_groups + 1)
4343
lc = left_count[i]
4444
rc = right_count[i]
@@ -113,7 +113,7 @@ function DataArrays.PooledDataArray{R}(df::AbstractDataFrame, ::Type{R})
113113
# might be faster.
114114
refs = zeros(R, nrow(df))
115115
poolref = Dict{AbstractDataFrame, Int}()
116-
pool = Array(UInt64, 0)
116+
pool = Vector{UInt64}(0)
117117
j = 1
118118
for i = 1:nrow(df)
119119
val = df[i,:]
@@ -188,7 +188,7 @@ join(name, job, kind = :cross)
188188
"""
189189
function Base.join(df1::AbstractDataFrame,
190190
df2::AbstractDataFrame;
191-
on::@compat(Union{Symbol, Vector{Symbol}}) = Symbol[],
191+
on::Union{Symbol, Vector{Symbol}} = Symbol[],
192192
kind::Symbol = :inner)
193193
if kind == :cross
194194
if on != Symbol[]

Diff for: src/abstractdataframe/reshape.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ end
102102
Stacks a DataFrame; convert from a wide to long format; see
103103
`stack`.
104104
"""
105-
melt(df::AbstractDataFrame, id_vars::@compat(Union{Int,Symbol})) = melt(df, [id_vars])
105+
melt(df::AbstractDataFrame, id_vars::Union{Int,Symbol}) = melt(df, [id_vars])
106106
function melt(df::AbstractDataFrame, id_vars)
107107
id_inds = index(df)[id_vars]
108108
stack(df, _setdiff(1:ncol(df), id_inds), id_inds)
@@ -173,8 +173,8 @@ function unstack(df::AbstractDataFrame, rowkey::Int, colkey::Int, value::Int)
173173
payload = DataFrame(Any[DataArray(eltype(valuecol), Nrow) for i in 1:Ncol], map(Symbol, keycol.pool))
174174
nowarning = true
175175
for k in 1:nrow(df)
176-
j = @compat Int(keycol.refs[k])
177-
i = @compat Int(refkeycol.refs[k])
176+
j = Int(keycol.refs[k])
177+
i = Int(refkeycol.refs[k])
178178
if i > 0 && j > 0
179179
if nowarning && !isna(payload[j][i])
180180
warn("Duplicate entries in unstack.")
@@ -206,10 +206,10 @@ function unstack(df::AbstractDataFrame, colkey::Int, value::Int)
206206
keys = unique(keycol)
207207
Nrow = length(g)
208208
Ncol = length(keycol.pool)
209-
df2 = DataFrame(Any[DataArray(fill(valuecol[1], Nrow), fill(true, Nrow)) for i in 1:Ncol], map(@compat(Symbol), keycol.pool))
209+
df2 = DataFrame(Any[DataArray(fill(valuecol[1], Nrow), fill(true, Nrow)) for i in 1:Ncol], map(Symbol, keycol.pool))
210210
nowarning = true
211211
for k in 1:nrow(df)
212-
j = @compat Int(keycol.refs[k])
212+
j = Int(keycol.refs[k])
213213
i = rowkey[k]
214214
if i > 0 && j > 0
215215
if nowarning && !isna(df2[j][i])

0 commit comments

Comments
 (0)