Skip to content

Commit b0507f3

Browse files
temporary work-around for JuliaIO/DiskArrays.jl#138 for the most common case
1 parent 621a74e commit b0507f3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/select.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,25 @@ macro select(v,expression)
251251
return Expr(:call,:select,esc(v),args...)
252252
end
253253

254+
255+
256+
# transform the ranges if possible to avoid issue
257+
# https://github.com/meggart/DiskArrays.jl/issues/138
258+
# for the most common case
259+
_maybetorange(v) = v
260+
function _maybetorange(v::AbstractVector)
261+
if isempty(v)
262+
return v
263+
end
264+
265+
r = v[begin]:v[end]
266+
if v == r
267+
return r
268+
else
269+
return v
270+
end
271+
end
272+
254273
"""
255274
vsubset = CommonDataModel.select(v,param1 => condition1, param2 => condition2,...)
256275
dssubset = CommonDataModel.select(ds,param1 => condition1, param2 => condition2,...)
@@ -334,9 +353,9 @@ function select(v,conditions...)
334353
end
335354

336355
if v isa AbstractArray
337-
view(v, indices...)
356+
view(v, _maybetorange.(indices)...)
338357
else
339-
view(v; indices...)
358+
view(v; ((k=>_maybetorange(v)) for (k,v) in indices)...)
340359
end
341360
end
342361

0 commit comments

Comments
 (0)