Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecations and CategoricalArrays.jl dependency #2554

Merged
merged 10 commits into from
Nov 27, 2020
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# DataFrames v1.0 Release Notes

## Breaking changes

* No breaking changes are planned for v1.0 release

## Bug fixes

## New functionalities


## Deprecated

* all old deprecations now throw an error
([#2554](https://github.com/JuliaData/DataFrames.jl/pull/2554))

## Dependency changes


## Other relevant changes


# DataFrames v0.22 Release Notes

## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion src/DataFrames.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DataFrames

using Statistics, Printf, REPL
using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays, CategoricalArrays
using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays
@reexport using Missings, InvertedIndices
using Base.Sort, Base.Order, Base.Iterators
using TableTraits, IteratorInterfaceExtensions
Expand Down
15 changes: 5 additions & 10 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,11 @@ julia> describe(df, :min, sum => :sum, cols=:x)
1 │ x 0.1 5.5
```
"""
function DataAPI.describe(df::AbstractDataFrame, stats::Union{Symbol,
Pair{<:Base.Callable, <:SymbolOrString},
Pair{<:SymbolOrString}}...; # TODO: remove after deprecation
cols=:)
if any(x -> x isa Pair{<:SymbolOrString}, stats)
Base.depwarn("name => function order is deprecated; use function => name instead", :describe)
end
return _describe(select(df, cols, copycols=false),
Any[s isa Pair{<:SymbolOrString} ? last(s) => first(s) : s for s in stats])
end
DataAPI.describe(df::AbstractDataFrame,
stats::Union{Symbol, Pair{<:Base.Callable, <:SymbolOrString}}...;
cols=:) =
_describe(select(df, cols, copycols=false), Any[s for s in stats])

DataAPI.describe(df::AbstractDataFrame; cols=:) =
_describe(select(df, cols, copycols=false),
[:mean, :min, :median, :max, :nmissing, :eltype])
Expand Down
4 changes: 0 additions & 4 deletions src/abstractdataframe/selection.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# TODO:
# * add handling of empty ByRow to filter, and select/transform/combine for GroupedDataFrame
# * add handling of multiple column return rules for select/transform/combine for GroupedDataFrame

# normalize_selection function makes sure that whatever input format of idx is it
# will end up in one of four canonical forms
# 1) AbstractVector{Int}
Expand Down
47 changes: 24 additions & 23 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,30 @@ function DataFrame(columns::AbstractMatrix, cnames::Symbol)
return DataFrame(columns, gennames(size(columns, 2)), makeunique=false)
end

# Discontinued constructors
bkamins marked this conversation as resolved.
Show resolved Hide resolved

DataFrame(matrix::Matrix) =
throw(ArgumentError("`DataFrame` constructor from a `Matrix` requires " *
"passing :auto as a second argument to automatically " *
"generate column names: `DataFrame(matrix, :auto)`"))

DataFrame(vecs::Vector{<:AbstractVector}) =
throw(ArgumentError("`DataFrame` constructor from a `Vector` of vectors requires " *
"passing :auto as a second argument to automatically " *
"generate column names: `DataFrame(vecs, :auto)`"))

DataFrame(column_eltypes::AbstractVector{T}, cnames::AbstractVector{Symbol},
nrows::Integer=0; makeunique::Bool=false) where T<:Type =
throw(ArgumentError("`DataFrame` constructor with passed eltypes is " *
"deprecated. Pass explicitly created columns to a " *
"`DataFrame` constructor instead."))

DataFrame(column_eltypes::AbstractVector{<:Type}, cnames::AbstractVector{<:AbstractString},
nrows::Integer=0; makeunique::Bool=false) where T<:Type =
throw(ArgumentError("`DataFrame` constructor with passed eltypes is " *
"deprecated. Pass explicitly created columns to a " *
"`DataFrame` constructor instead."))


##############################################################################
##
Expand Down Expand Up @@ -484,17 +508,6 @@ Base.getindex(df::DataFrame, row_ind::typeof(!),
##
##############################################################################

function nextcolname(df::DataFrame)
col = Symbol(string("x", ncol(df) + 1))
hasproperty(df, col) || return col
i = 1
while true
col = Symbol(string("x", ncol(df) + 1, "_", i))
hasproperty(df, col) || return col
i += 1
end
end

# Will automatically add a new column if needed
function insert_single_column!(df::DataFrame, v::AbstractVector, col_ind::ColumnIndex)
if ncol(df) != 0 && nrow(df) != length(v)
Expand Down Expand Up @@ -524,18 +537,6 @@ function insert_single_entry!(df::DataFrame, v::Any, row_ind::Integer, col_ind::
end
end

function insert_multiple_entries!(df::DataFrame,
v::Any,
row_inds::AbstractVector,
col_ind::ColumnIndex)
if haskey(index(df), col_ind)
_columns(df)[index(df)[col_ind]][row_inds] .= v
return v
else
throw(ArgumentError("Cannot assign to non-existent column: $col_ind"))
end
end

# df[!, SingleColumnIndex] = AbstractVector
function Base.setindex!(df::DataFrame, v::AbstractVector, ::typeof(!), col_ind::ColumnIndex)
insert_single_column!(df, v, col_ind)
Expand Down
141 changes: 2 additions & 139 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,147 +1,10 @@
import Base: @deprecate
# commenting out till we decide to start deprecating things again

@deprecate DataFrame!(args...; kwargs...) DataFrame(args...; copycols=false, kwargs...)
# import Base: @deprecate

# 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."))
bkamins marked this conversation as resolved.
Show resolved Hide resolved

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)
bkamins marked this conversation as resolved.
Show resolved Hide resolved

@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))))
9 changes: 9 additions & 0 deletions test/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,13 @@ end

end

@testset "removed constructors" begin
@test_throws ArgumentError DataFrame([1 2; 3 4])
@test_throws ArgumentError DataFrame([[1, 2], [3, 4]])
@test_throws ArgumentError DataFrame([Int, Float64], [:a, :b])
@test_throws ArgumentError DataFrame([Int, Float64], [:a, :b], 2)
@test_throws ArgumentError DataFrame([Int, Float64], ["a", "b"])
@test_throws ArgumentError DataFrame([Int, Float64], ["a", "b"], 2)
end

end # module
1 change: 1 addition & 0 deletions test/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ end
DataFrame(variable=:a, min=1, min2=1, max2=2, max=2)

@test_throws ArgumentError describe(df, :mean, :all)
@test_throws MethodError describe(DataFrame(a=[1, 2]), cols = :a, "max2" => maximum)
end

@testset "append!" begin
Expand Down
Loading