From 863b70c217584cc3234353a6622dbdffb2498259 Mon Sep 17 00:00:00 2001 From: Chandu-4444 Date: Fri, 19 Nov 2021 19:37:19 +0530 Subject: [PATCH 01/17] Add examples for `issorted` docstrings. --- src/abstractdataframe/sort.jl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 410cd0aebf..6e2288e0a8 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -336,13 +336,40 @@ Sort.defalg(df::AbstractDataFrame, o::Ordering; alg=nothing, cols=[]) = lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) Test whether data frame `df` sorted by column(s) `cols`. +If no column is specified, it checks if the `df` is sorted lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). If `rev` is `true`, reverse sorting is performed. To enable reverse sorting only for some columns, pass `order(c, rev=true)` in `cols`, with `c` the corresponding column index (see example below). + See other methods for a description of other keyword arguments. + +# Examples +```jldoctest +julia> df = DataFrame(a = [1,2,3,4], b = [4,3,2,1]) +4×2 DataFrame + Row │ a b + │ Int64 Int64 +─────┼────────────── + 1 │ 1 4 + 2 │ 2 3 + 3 │ 3 2 + 4 │ 4 1 + +julia> issorted(df) +true + +julia> issorted(df, :a) +true + +julia> issorted(df, :b) +false + +julia> issorted(df, :b, rev = true) +true +``` """ function Base.issorted(df::AbstractDataFrame, cols=[]; lt=isless, by=identity, rev=false, order=Forward) @@ -448,6 +475,7 @@ end Return a permutation vector of row indices of data frame `df` that puts them in sorted order according to column(s) `cols`. +If `cols` were not specified, it returns row indices that sorts `df` lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). From 86ebca0cb57b7f7e9ade7dd087f466ed9749d878 Mon Sep 17 00:00:00 2001 From: Chandra Kiran G <52241074+Chandu-4444@users.noreply.github.com> Date: Sat, 20 Nov 2021 11:51:59 +0530 Subject: [PATCH 02/17] Update src/abstractdataframe/sort.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bogumił Kamiński --- src/abstractdataframe/sort.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 6e2288e0a8..a17110118f 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -367,7 +367,7 @@ true julia> issorted(df, :b) false -julia> issorted(df, :b, rev = true) +julia> issorted(df, :b, rev=true) true ``` """ From 90ca4f18611cb57e58a0302b8454c0bd18994702 Mon Sep 17 00:00:00 2001 From: Chandu-4444 Date: Sat, 20 Nov 2021 12:03:26 +0530 Subject: [PATCH 03/17] Add more description in docstrings when column selector is not specified. --- src/abstractdataframe/sort.jl | 4 +++- src/dataframe/sort.jl | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index a17110118f..06765a574d 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -336,7 +336,7 @@ Sort.defalg(df::AbstractDataFrame, o::Ordering; alg=nothing, cols=[]) = lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) Test whether data frame `df` sorted by column(s) `cols`. -If no column is specified, it checks if the `df` is sorted lexicographically. +If column selector selects no columns, it checks if the `df` is sorted lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). @@ -395,6 +395,7 @@ Return a data frame containing the rows in `df` sorted by column(s) `cols`. Sorting on multiple columns is done lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). +If column selector selects no columns, then the sorting would be done lexicographically. If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending @@ -478,6 +479,7 @@ sorted order according to column(s) `cols`. If `cols` were not specified, it returns row indices that sorts `df` lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). +If column selector selects no columns, it returns row indices that sorts `df` lexicographically. If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending diff --git a/src/dataframe/sort.jl b/src/dataframe/sort.jl index b1d88f7fe0..1838f9e932 100755 --- a/src/dataframe/sort.jl +++ b/src/dataframe/sort.jl @@ -8,6 +8,7 @@ Sort data frame `df` by column(s) `cols`. Sorting on multiple columns is done lexicographicallly. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). +If column selector selects no columns, it sorts the `df` lexicographically. If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending From 9645de43046be53fad4e03a27afbe8898b12484b Mon Sep 17 00:00:00 2001 From: Chandra Kiran G <52241074+Chandu-4444@users.noreply.github.com> Date: Sat, 20 Nov 2021 21:42:35 +0530 Subject: [PATCH 04/17] Update src/abstractdataframe/sort.jl Co-authored-by: Milan Bouchet-Valat --- src/abstractdataframe/sort.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 06765a574d..4369ca2838 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -336,7 +336,7 @@ Sort.defalg(df::AbstractDataFrame, o::Ordering; alg=nothing, cols=[]) = lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) Test whether data frame `df` sorted by column(s) `cols`. -If column selector selects no columns, it checks if the `df` is sorted lexicographically. +If `cols` selects no columns, check whether `df` is sorted on all columns. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). From bfd3b5b81376c5df0c388bf543a342bbfb0a2690 Mon Sep 17 00:00:00 2001 From: Chandra Kiran G <52241074+Chandu-4444@users.noreply.github.com> Date: Sat, 20 Nov 2021 21:42:46 +0530 Subject: [PATCH 05/17] Update src/abstractdataframe/sort.jl Co-authored-by: Milan Bouchet-Valat --- src/abstractdataframe/sort.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 4369ca2838..0aff32d03b 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -395,7 +395,7 @@ Return a data frame containing the rows in `df` sorted by column(s) `cols`. Sorting on multiple columns is done lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). -If column selector selects no columns, then the sorting would be done lexicographically. +If `cols` selects no columns, sort `df` on all columns. If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending From 3e6e07919137b5df3178aec9f41434817aa86acb Mon Sep 17 00:00:00 2001 From: Chandra Kiran G <52241074+Chandu-4444@users.noreply.github.com> Date: Sat, 20 Nov 2021 21:43:12 +0530 Subject: [PATCH 06/17] Update src/abstractdataframe/sort.jl Co-authored-by: Milan Bouchet-Valat --- src/abstractdataframe/sort.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 0aff32d03b..389d09367d 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -479,7 +479,7 @@ sorted order according to column(s) `cols`. If `cols` were not specified, it returns row indices that sorts `df` lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). -If column selector selects no columns, it returns row indices that sorts `df` lexicographically. +If `cols` selects no columns, return permutation vector based on sorting all columns. If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending From 898c36130b1ae812f83af79ab25fc665aa5e760b Mon Sep 17 00:00:00 2001 From: Chandra Kiran G <52241074+Chandu-4444@users.noreply.github.com> Date: Sat, 20 Nov 2021 21:43:21 +0530 Subject: [PATCH 07/17] Update src/dataframe/sort.jl Co-authored-by: Milan Bouchet-Valat --- src/dataframe/sort.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dataframe/sort.jl b/src/dataframe/sort.jl index 1838f9e932..c00ee3349d 100755 --- a/src/dataframe/sort.jl +++ b/src/dataframe/sort.jl @@ -8,7 +8,7 @@ Sort data frame `df` by column(s) `cols`. Sorting on multiple columns is done lexicographicallly. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). -If column selector selects no columns, it sorts the `df` lexicographically. +If `cols` selects no columns, sort `df` on all columns. If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending From 8bdd0de96ea646fcd27c3a744ff72885d4321596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 17:15:58 +0100 Subject: [PATCH 08/17] change [] to All() as a default in sorting --- src/abstractdataframe/sort.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 389d09367d..268e5f771e 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -332,7 +332,7 @@ Sort.defalg(df::AbstractDataFrame, o::Ordering; alg=nothing, cols=[]) = ######################## """ - issorted(df::AbstractDataFrame, cols; + issorted(df::AbstractDataFrame, cols=All(); lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) Test whether data frame `df` sorted by column(s) `cols`. @@ -371,7 +371,7 @@ julia> issorted(df, :b, rev=true) true ``` """ -function Base.issorted(df::AbstractDataFrame, cols=[]; +function Base.issorted(df::AbstractDataFrame, cols=All(); lt=isless, by=identity, rev=false, order=Forward) # exclude AbstractVector as in that case cols can contain order(...) clauses if cols isa MultiColumnIndex && !(cols isa AbstractVector) @@ -387,7 +387,7 @@ function Base.issorted(df::AbstractDataFrame, cols=[]; end """ - sort(df::AbstractDataFrame, cols; + sort(df::AbstractDataFrame, cols=All(); alg::Union{Algorithm, Nothing}=nothing, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward, view::Bool=false) @@ -463,14 +463,14 @@ julia> sort(df, [:x, order(:y, rev=true)]) 4 │ 3 b ``` """ -@inline function Base.sort(df::AbstractDataFrame, cols=[]; alg=nothing, lt=isless, +@inline function Base.sort(df::AbstractDataFrame, cols=All(); alg=nothing, lt=isless, by=identity, rev=false, order=Forward, view::Bool=false) rowidxs = sortperm(df, cols, alg=alg, lt=lt, by=by, rev=rev, order=order) return view ? Base.view(df, rowidxs, :) : df[rowidxs, :] end """ - sortperm(df::AbstractDataFrame, cols; + sortperm(df::AbstractDataFrame, cols=All(); alg::Union{Algorithm, Nothing}=nothing, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) @@ -532,7 +532,7 @@ julia> sortperm(df, [:x, order(:y, rev=true)]) 1 ``` """ -function Base.sortperm(df::AbstractDataFrame, cols=[]; +function Base.sortperm(df::AbstractDataFrame, cols=All(); alg=nothing, lt=isless, by=identity, rev=false, order=Forward) if !(by isa Base.Callable || (by isa AbstractVector && eltype(by) <: Base.Callable)) msg = "'by' must be a Function or a vector of Functions. " * From 3cef39e3f31d5176423b49cec3b4631f8d08b0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 17:16:40 +0100 Subject: [PATCH 09/17] change [] to All() in sort! --- src/dataframe/sort.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dataframe/sort.jl b/src/dataframe/sort.jl index c00ee3349d..2aa9436708 100755 --- a/src/dataframe/sort.jl +++ b/src/dataframe/sort.jl @@ -1,6 +1,6 @@ """ - sort!(df::AbstractDataFrame, cols; + sort!(df::AbstractDataFrame, cols=All(); alg::Union{Algorithm, Nothing}=nothing, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) @@ -73,7 +73,7 @@ julia> sort!(df, [:x, order(:y, rev=true)]) 4 │ 3 b ``` """ -function Base.sort!(df::DataFrame, cols=[]; alg=nothing, +function Base.sort!(df::DataFrame, cols=All(); alg=nothing, lt=isless, by=identity, rev=false, order=Forward) if !(isa(by, Function) || eltype(by) <: Function) msg = "'by' must be a Function or a vector of Functions. " * From 087eadbbf26de9bbfd89e3b47fe2771f2b98dc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 17:18:28 +0100 Subject: [PATCH 10/17] Update NEWS.md --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index c656a6c5f5..c72008ee2c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -112,6 +112,9 @@ * `delete!` is deprecated in favor of `deleteat!` ([#2854](https://github.com/JuliaData/DataFrames.jl/issues/2854)) +* In `sort`, `sort!`, `issorted` and `soerperm` it is now documented + that passing an empty column selector leads to an undefined result + ([#2941](https://github.com/JuliaData/DataFrames.jl/issues/2941)) ## Planned changes From b8e44e62b30be85f1536d5e10a09c070c2e1f8f9 Mon Sep 17 00:00:00 2001 From: Chandu-4444 Date: Sat, 20 Nov 2021 23:22:15 +0530 Subject: [PATCH 11/17] Add deprecation warning to `sort` and related functions's docstrings. --- src/abstractdataframe/sort.jl | 9 ++++++--- src/dataframe/sort.jl | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 268e5f771e..12d72657e6 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -336,7 +336,8 @@ Sort.defalg(df::AbstractDataFrame, o::Ordering; alg=nothing, cols=[]) = lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) Test whether data frame `df` sorted by column(s) `cols`. -If `cols` selects no columns, check whether `df` is sorted on all columns. +If `cols` selects no columns, check whether `df` is sorted on all columns +(this behaviour is deprecated and will change in future versions). `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). @@ -395,7 +396,8 @@ Return a data frame containing the rows in `df` sorted by column(s) `cols`. Sorting on multiple columns is done lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). -If `cols` selects no columns, sort `df` on all columns. +If `cols` selects no columns, sort `df` on all columns +(this behaviour is deprecated and will change in future versions). If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending @@ -476,7 +478,8 @@ end Return a permutation vector of row indices of data frame `df` that puts them in sorted order according to column(s) `cols`. -If `cols` were not specified, it returns row indices that sorts `df` lexicographically. +If `cols` were not specified, it returns row indices that sorts `df` lexicographically +(this behaviour is deprecated and will change in future versions). `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). If `cols` selects no columns, return permutation vector based on sorting all columns. diff --git a/src/dataframe/sort.jl b/src/dataframe/sort.jl index 2aa9436708..563e7ee11d 100755 --- a/src/dataframe/sort.jl +++ b/src/dataframe/sort.jl @@ -8,7 +8,8 @@ Sort data frame `df` by column(s) `cols`. Sorting on multiple columns is done lexicographicallly. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). -If `cols` selects no columns, sort `df` on all columns. +If `cols` selects no columns, sort `df` on all columns +(this behaviour is deprecated and will change in future versions). If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending From f45e63c711f3e954599313ec05c4900c26b347dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 21:39:21 +0100 Subject: [PATCH 12/17] Apply suggestions from code review --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index c72008ee2c..10b4c754c4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -113,7 +113,8 @@ * `delete!` is deprecated in favor of `deleteat!` ([#2854](https://github.com/JuliaData/DataFrames.jl/issues/2854)) * In `sort`, `sort!`, `issorted` and `soerperm` it is now documented - that passing an empty column selector leads to an undefined result + that the result of passing an empty column selector uses lexicographic + ordering of all columns, but this behavior is deprecated. ([#2941](https://github.com/JuliaData/DataFrames.jl/issues/2941)) ## Planned changes From f8db3fa53d18626718128902b157976137d80205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 21:40:47 +0100 Subject: [PATCH 13/17] Update src/abstractdataframe/sort.jl --- src/abstractdataframe/sort.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 12d72657e6..a79764eb62 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -336,6 +336,8 @@ Sort.defalg(df::AbstractDataFrame, o::Ordering; alg=nothing, cols=[]) = lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) Test whether data frame `df` sorted by column(s) `cols`. +Checking against multiple columns is done lexicographically. + If `cols` selects no columns, check whether `df` is sorted on all columns (this behaviour is deprecated and will change in future versions). From 99d3bfed80c90ea8b6487ad628dab9a8dfe6850f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 21:43:18 +0100 Subject: [PATCH 14/17] Apply suggestions from code review --- src/abstractdataframe/sort.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index a79764eb62..441fe697e3 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -351,7 +351,7 @@ See other methods for a description of other keyword arguments. # Examples ```jldoctest -julia> df = DataFrame(a = [1,2,3,4], b = [4,3,2,1]) +julia> df = DataFrame(a = [1, 2, 3, 4], b = [4, 3, 2, 1]) 4×2 DataFrame Row │ a b │ Int64 Int64 @@ -480,7 +480,9 @@ end Return a permutation vector of row indices of data frame `df` that puts them in sorted order according to column(s) `cols`. -If `cols` were not specified, it returns row indices that sorts `df` lexicographically +Order on multiple columns is done lexicographically. + +If `cols` select no columns, it returns row indices that sorts `df` lexicographically (this behaviour is deprecated and will change in future versions). `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). From fc834f0147e6305b8e884c1394512fe309b3204b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 21:44:40 +0100 Subject: [PATCH 15/17] Update src/abstractdataframe/sort.jl --- src/abstractdataframe/sort.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 441fe697e3..a1ca2a53c2 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -338,6 +338,7 @@ Sort.defalg(df::AbstractDataFrame, o::Ordering; alg=nothing, cols=[]) = Test whether data frame `df` sorted by column(s) `cols`. Checking against multiple columns is done lexicographically. +`cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). If `cols` selects no columns, check whether `df` is sorted on all columns (this behaviour is deprecated and will change in future versions). From 35c86751b37e2e6b46ca67ed52a1bcc520389f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 20 Nov 2021 21:48:53 +0100 Subject: [PATCH 16/17] Update sort.jl --- src/abstractdataframe/sort.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index a1ca2a53c2..6df4709da9 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -209,6 +209,8 @@ function ordering(df::AbstractDataFrame, cols::AbstractVector, lt::Function, by::Function, rev::Bool, order::Ordering) if length(cols) == 0 + Base.depwarn("When empty column selector is passed ordering is done on all colums. " * + "This behavior is deprecated and will change in the future.", :ordering) return ordering(df, lt, by, rev, order) end From 8e06298f41823e959b0155927dd8f78735caaa0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 21 Nov 2021 00:08:07 +0100 Subject: [PATCH 17/17] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- NEWS.md | 2 +- src/abstractdataframe/sort.jl | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 10b4c754c4..2892be3289 100644 --- a/NEWS.md +++ b/NEWS.md @@ -112,7 +112,7 @@ * `delete!` is deprecated in favor of `deleteat!` ([#2854](https://github.com/JuliaData/DataFrames.jl/issues/2854)) -* In `sort`, `sort!`, `issorted` and `soerperm` it is now documented +* In `sort`, `sort!`, `issorted` and `sortperm` it is now documented that the result of passing an empty column selector uses lexicographic ordering of all columns, but this behavior is deprecated. ([#2941](https://github.com/JuliaData/DataFrames.jl/issues/2941)) diff --git a/src/abstractdataframe/sort.jl b/src/abstractdataframe/sort.jl index 6df4709da9..f3bcaa056b 100755 --- a/src/abstractdataframe/sort.jl +++ b/src/abstractdataframe/sort.jl @@ -483,13 +483,11 @@ end Return a permutation vector of row indices of data frame `df` that puts them in sorted order according to column(s) `cols`. -Order on multiple columns is done lexicographically. - -If `cols` select no columns, it returns row indices that sorts `df` lexicographically -(this behaviour is deprecated and will change in future versions). +Order on multiple columns is computed lexicographically. `cols` can be any column selector ($COLUMNINDEX_STR; $MULTICOLUMNINDEX_STR). -If `cols` selects no columns, return permutation vector based on sorting all columns. +If `cols` selects no columns, return permutation vector based on sorting all columns +(this behaviour is deprecated and will change in future versions). If `alg` is `nothing` (the default), the most appropriate algorithm is chosen automatically among `TimSort`, `MergeSort` and `RadixSort` depending