/
deprecated.jl
147 lines (134 loc) · 7.67 KB
/
deprecated.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import Base: @deprecate
@deprecate DataFrame!(args...; kwargs...) DataFrame(args...; copycols=false, kwargs...)
# TODO: remove these definitions in year 2021
by(args...; kwargs...) = throw(ArgumentError("by function was removed from DataFrames.jl. " *
"Use the `combine(groupby(...), ...)` or `combine(f, groupby(...))` instead."))
aggregate(args...; kwargs...) = throw(ArgumentError("aggregate function was removed from DataFrames.jl. " *
"Use the `combine` function instead."))
export categorical, categorical!
function CategoricalArrays.categorical(df::AbstractDataFrame,
cols::Union{ColumnIndex, MultiColumnIndex};
compress::Union{Bool, Nothing}=nothing)
if compress === nothing
compress = false
categoricalstr = "categorical"
else
categoricalstr = "(x -> categorical(x, compress=$compress))"
end
if cols isa AbstractVector{<:Union{AbstractString, Symbol}}
Base.depwarn("`categorical(df, cols)` is deprecated. " *
"Use `transform(df, cols .=> $categoricalstr, renamecols=false)` instead.",
:categorical)
return transform(df, cols .=> (x -> categorical(x, compress=compress)), renamecols=false)
elseif cols isa Union{AbstractString, Symbol}
Base.depwarn("`categorical(df, cols)` is deprecated. " *
"Use `transform(df, cols => $categoricalstr, renamecols=false)` instead.",
:categorical)
return transform(df, cols => (x -> categorical(x, compress=compress)), renamecols=false)
else
Base.depwarn("`categorical(df, cols)` is deprecated. " *
"Use `transform(df, names(df, cols) .=> $categoricalstr, renamecols=false)` instead.",
:categorical)
return transform(df, names(df, cols) .=> (x -> categorical(x, compress=compress)), renamecols=false)
end
end
function CategoricalArrays.categorical(df::AbstractDataFrame,
cols::Union{Type, Nothing}=nothing;
compress::Bool=false)
if compress === nothing
compress = false
categoricalstr = "categorical"
else
categoricalstr = "categorical(x, compress=$compress)"
end
if cols === nothing
cols = Union{AbstractString, Missing}
Base.depwarn("`categorical(df)` is deprecated. " *
"Use `transform(df, names(df, $cols) .=> $categoricalstr, renamecols=false)` instead.",
:categorical)
else
Base.depwarn("`categorical(df, T)` is deprecated. " *
"Use transform(df, names(df, T) .=> $categoricalstr, renamecols=false)` instead.",
:categorical)
end
return transform(df, names(df, cols) .=> (x -> categorical(x, compress=compress)), renamecols=false)
end
function categorical!(df::DataFrame, cols::Union{ColumnIndex, MultiColumnIndex};
compress::Union{Bool, Nothing}=nothing)
if compress === nothing
compress = false
categoricalstr = "categorical"
else
categoricalstr = "(x -> categorical(x, compress=$compress))"
end
if cols isa AbstractVector{<:Union{AbstractString, Symbol}}
Base.depwarn("`categorical!(df, cols)` is deprecated. " *
"Use `transform!(df, cols .=> $categoricalstr, renamecols=false)` instead.",
:categorical!)
return transform!(df, cols .=> (x -> categorical(x, compress=compress)), renamecols=false)
elseif cols isa Union{AbstractString, Symbol}
Base.depwarn("`categorical!(df, cols)` is deprecated. " *
"Use `transform!(df, cols => $categoricalstr, renamecols=false)` instead.",
:categorical!)
return transform!(df, cols => (x -> categorical(x, compress=compress)), renamecols=false)
else
Base.depwarn("`categorical!(df, cols)` is deprecated. " *
"Use `transform!(df, names(df, cols) .=> $categoricalstr, renamecols=false)` instead.",
:categorical!)
return transform!(df, names(df, cols) .=> (x -> categorical(x, compress=compress)), renamecols=false)
end
end
function categorical!(df::DataFrame, cols::Union{Type, Nothing}=nothing;
compress::Bool=false)
if compress === nothing
compress = false
categoricalstr = "categorical"
else
categoricalstr = "(x -> categorical(x, compress=$compress))"
end
if cols === nothing
cols = Union{AbstractString, Missing}
Base.depwarn("`categorical!(df)` is deprecated. " *
"Use `transform!(df, names(df, $cols) .=> $categoricalstr, renamecols=false)` instead.",
:categorical!)
else
Base.depwarn("`categorical!(df, T)` is deprecated. " *
"Use `transform!(df, names(df, T) .=> $categoricalstr, renamecols=false)` instead.",
:categorical!)
end
return transform!(df, names(df, cols) .=> (x -> categorical(x, compress=compress)), renamecols=false)
end
@deprecate DataFrame(pairs::NTuple{N, Pair}; makeunique::Bool=false,
copycols::Bool=true) where {N} DataFrame(pairs..., makeunique=makeunique, copycols=copycols)
@deprecate DataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, Symbol}; makeunique::Bool=false,
copycols::Bool=true) where {N} DataFrame(collect(columns), collect(cnames);
makeunique=makeunique, copycols=copycols)
@deprecate DataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, AbstractString}; makeunique::Bool=false,
copycols::Bool=true) where {N} DataFrame(collect(columns), [Symbol(c) for c in cnames];
makeunique=makeunique, copycols=copycols)
@deprecate DataFrame(columns::NTuple{N, AbstractVector};
copycols::Bool=true) where {N} DataFrame(collect(columns),
Symbol.(:x, 1:length(columns)), copycols=copycols)
# this deprecation is very important, becuase without it users will
# get strange results with old code as described in https://github.com/JuliaData/Tables.jl/issues/208
@deprecate DataFrame(columns::AbstractVector{<:AbstractVector}; makeunique::Bool=false,
copycols::Bool=true) DataFrame(columns, :auto, copycols=copycols)
@deprecate DataFrame(columns::AbstractMatrix) DataFrame(columns, :auto)
function DataFrame(column_eltypes::AbstractVector{T}, cnames::AbstractVector{Symbol},
nrows::Integer=0; makeunique::Bool=false)::DataFrame where T<:Type
Base.depwarn("`DataFrame` constructor with passed eltypes is deprecated. " *
"Pass explicitly created columns to a `DataFrame` constructor instead.",
:DataFrame)
columns = AbstractVector[elty >: Missing ?
fill!(Tables.allocatecolumn(elty, nrows), missing) :
Tables.allocatecolumn(elty, nrows)
for elty in column_eltypes]
return DataFrame(columns, Index(convert(Vector{Symbol}, cnames),
makeunique=makeunique), copycols=false)
end
DataFrame(column_eltypes::AbstractVector{<:Type},
cnames::AbstractVector{<:AbstractString},
nrows::Integer=0; makeunique::Bool=false) =
DataFrame(column_eltypes, Symbol.(cnames), nrows; makeunique=makeunique)
import Base: convert
@deprecate convert(::Type{DataFrame}, A::AbstractMatrix) DataFrame(Tables.table(A, header=Symbol.(:x, axes(A, 2))))