Skip to content

Commit d3feeef

Browse files
committed
fix bug - subdataset with zero column
1 parent 528be73 commit d3feeef

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# Dev
22

3+
## Fixes
4+
5+
* Fix issue with `QuickSortAlg` in future version of Julia
6+
* Empty the rows of a `SubDataset` without columns
7+
8+
# Version 0.7.12
9+
310
## Features
411

512
* Users can use `resize!` to resize a data set
613

714
## Fixes
815

916
* Fix function signature for some stat functions
17+
1018
# Version 0.7.11
1119

1220
## Features

src/subdataset/subdataset.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ Base.@propagate_inbounds function SubDataset(parent::Dataset, rows::AbstractVect
108108
@boundscheck if !checkindex(Bool, axes(parent, 1), rows)
109109
throw(BoundsError(parent, (rows, cols)))
110110
end
111-
SubDataset(parent, SubIndex(index(parent), cols), rows)
111+
sindex = SubIndex(index(parent), cols)
112+
# SubDataset without columns should not have any row
113+
if all(==(0), sindex.remap)
114+
SubDataset(parent, sindex, Int[])
115+
else
116+
SubDataset(parent,sindex , rows)
117+
end
112118
end
113119
Base.@propagate_inbounds SubDataset(parent::Dataset, ::Colon, cols) =
114120
SubDataset(parent, axes(parent, 1), cols)

test/subdataset.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,43 @@ end
297297
SubDataset(sds, [1, 1, 1], :)
298298
end
299299
end
300+
@testset "subdataset with no columns" begin # from DF.jl
301+
ds = Dataset(a=1:3, b=4:6)
302+
vds = @view ds[[3, 1], 2:1]
303+
@test nrow(SubDataset(vds, Int[], :)) == 0
304+
@test nrow(SubDataset(vds, Bool[], :)) == 0
305+
@test nrow(SubDataset(vds, :, :)) == 0
306+
@test nrow(SubDataset(vds, Not(:), :)) == 0
307+
@test nrow(SubDataset(vds, Int[], [])) == 0
308+
@test nrow(SubDataset(vds, Bool[], [])) == 0
309+
@test nrow(SubDataset(vds, :, [])) == 0
310+
@test nrow(SubDataset(vds, Not(:), [])) == 0
311+
@test_throws BoundsError SubDataset(vds, [1, 2], :)
312+
313+
@test nrow(view(vds, Int[], :)) == 0
314+
@test nrow(view(vds, Bool[], :)) == 0
315+
@test nrow(view(vds, :, :)) == 0
316+
@test nrow(view(vds, !, :)) == 0
317+
@test nrow(view(vds, Not(:), :)) == 0
318+
@test nrow(view(vds, Int[], [])) == 0
319+
@test nrow(view(vds, Bool[], [])) == 0
320+
@test nrow(view(vds, :, [])) == 0
321+
@test nrow(view(vds, !, [])) == 0
322+
@test nrow(view(vds, Not(:), [])) == 0
323+
@test_throws BoundsError view(vds, [1, 2], :)
324+
325+
@test_throws BoundsError vds[1, 1]
326+
@test_throws BoundsError vds[[1, 2], 1]
327+
328+
@test nrow(getindex(vds, Int[], :)) == 0
329+
@test nrow(getindex(vds, Bool[], :)) == 0
330+
@test nrow(getindex(vds, :, :)) == 0
331+
@test nrow(getindex(vds, !, :)) == 0
332+
@test nrow(getindex(vds, Not(:), :)) == 0
333+
@test nrow(getindex(vds, Int[], [])) == 0
334+
@test nrow(getindex(vds, Bool[], [])) == 0
335+
@test nrow(getindex(vds, :, [])) == 0
336+
@test nrow(getindex(vds, !, [])) == 0
337+
@test nrow(getindex(vds, Not(:), [])) == 0
338+
@test_throws BoundsError getindex(vds, [1, 2], :)
339+
end

0 commit comments

Comments
 (0)