Skip to content

Commit e500c19

Browse files
Fix finding files for RasterSeries with a pattern (#1024)
* use startswith instead of indexing * test finding filenames with a pattern * sort files before testing equality * filter_ext is not base
1 parent 572711a commit e500c19

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/series.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,18 @@ function RasterSeries(path::AbstractString, dims;
184184
dirpath = path
185185
filepaths = filter_ext(dirpath, ext)
186186
length(filepaths) > 0 || error("No $(isnothing(ext) ? "" : ext) files found in \"$path\" dir")
187-
full_filename, _ = splitext(basename(first(filepaths)))
187+
full_filename, _ = Base.splitext(Base.basename(first(filepaths)))
188188
common_filename = join(split(full_filename, separator)[1:end-1])
189189
else
190-
dirpath = dirname(path)
191-
common_filename, path_ext = splitext(basename(path))
190+
dirpath = Base.dirname(path)
191+
common_filename, path_ext = Base.splitext(Base.basename(path))
192192
ext = (isnothing(ext) && path_ext != "") ? path_ext : ext
193193
filepaths = filter(filter_ext(dirpath, ext)) do fp
194-
basename(fp)[1:length(common_filename)] == common_filename
194+
Base.startswith(Base.basename(fp), common_filename)
195195
end
196196
length(filepaths) > 0 || error("No $(isnothing(ext) ? "" : ext) files found matching \"$common_filename\" stem and \"$ext\" extension")
197197
end
198-
basenames = map(fp -> basename(splitext(fp)[1]), filepaths)
198+
basenames = map(fp -> Base.basename(Base.splitext(fp)[1]), filepaths)
199199
v = val(dims)
200200
# Try to get values of the wrapped type from the filenames
201201
if dims isa Dimension && val(dims) isa Union{Type,AutoVal{<:Type}}

test/series.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,11 @@ end
127127
@test Rasters.isdisk(series)
128128
@test !Rasters.isdisk(read(series))
129129
@test Rasters.isdisk(Rasters.combine(series))
130+
131+
path = dirname(first(filenames))
132+
pattern = basename(first(filenames))[1:2]
133+
filename_pattern = joinpath(dirname(first(filenames)), "$pattern.tif")
134+
series2 = RasterSeries(filename_pattern, times; duplicate_first=true, lazy=true)
135+
@test isequal(sort(Rasters.filename.(series2)), sort(filenames))
130136
end
131137
end

0 commit comments

Comments
 (0)