Skip to content

Commit 7216ade

Browse files
authored
Fix deprecation warning when sorting data frame with no columns (#3190)
1 parent 94ac6cc commit 7216ade

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/abstractdataframe/sort.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ function ordering(df::AbstractDataFrame, cols::AbstractVector, lt::Function,
209209
by::Function, rev::Bool, order::Ordering)
210210

211211
if length(cols) == 0
212-
Base.depwarn("When empty column selector is passed ordering is done on all colums. " *
213-
"This behavior is deprecated and will change in the future.", :ordering)
212+
if ncol(df) > 0
213+
Base.depwarn("When empty column selector is passed ordering is done on all colums. " *
214+
"This behavior is deprecated and will change in the future.", :ordering)
215+
end
214216
return ordering(df, lt, by, rev, order)
215217
end
216218

src/other/metadata.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Metadata API from DataAPI.jl
22

3-
# private type that is passed as a default value in metadata and colmetadata
4-
# do detect the fact that no default was passed
3+
# private type that is passed as a default value in the metadata and colmetadata
4+
# functions to detect the fact that no default was passed
55
struct MetadataMissingDefault end
66

77
# DataAPI.metadatasupport and DataAPI.colmetadatasupport are not exported

test/sort.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ using DataFrames, Random, Test, CategoricalArrays
1010

1111
d = DataFrame(dv1=dv1, dv2=dv2, dv3=dv3, cv1=cv1)
1212

13+
@test sort(DataFrame()) == DataFrame()
14+
@test sort!(DataFrame()) == DataFrame()
15+
@test isempty(sortperm(DataFrame()))
16+
@test issorted(DataFrame())
1317
@test sortperm(d) == sortperm(dv1)
1418
@test sortperm(d[:, [:dv3, :dv1]]) == sortperm(dv3)
1519
@test sort(d, :dv1)[!, :dv3] == sort(d, "dv1")[!, "dv3"] == sortperm(dv1)

0 commit comments

Comments
 (0)