You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
S3FileSystem.find appears not to respect max_depth #378
When I call find(d, maxdepth=1) on a directory with 24 subdirectories, it returns not only the 24 subdirectories but also all the files contained in all those directories. That means, the output is:
24
2304
What you expected to happen:
Due to the maxdepth=1 parameter, I expected it would only return the 24 subdirectories. That means, I expect the output to be:
This makes globbing in higher level directories so slow as to be unusable. For example, a glob of "noaa-goes16/ABI-L1b-RadF/*" will call .find("noaa-goes16/ABI-L1b-RadF", maxdepth=1) which (ignoring the maxdepth parameter) will list the entire contents of the subdirectory, millions of files, and will take a very long time to complete.
Sorry about this, a case of choosing one optimisation over another.
#360 changed find to not be recursive, so that you can complete the request in a single call for a nested directory tree, because find is usually used to get everything. The previous version was usually slower except in the case you have before you, or a small value for depth.
We could resurrect the old code, and use it for the case that depth is small. What do you think?
I haven't followed the history so it's difficult for me to comment on the optimisation of find (and I don't understand the linked PR; from its diff it looks like the method didn't exist at all before?), but the current situation in which there exists a max_depth argument that is ignored (even without warning) seems undesirable. I'm not personally using find directly, but rather fs.glob("noaa-goes16/ABI-L1B-RadF/*") (or a different pattern, but with a single * only), so if find becomes too complicated when maintaining two approaches for small or large values of depth, then it would work for me if glob with a single * got its listing elsewhere (such as from ls?).
Oops, I just realised that the glob method implementation is not in s3fs at all, but inherited from s3fs.AbstractFileSystem. So it would still need to be resolved here (changing the implementation of find seems then more sensible than overloading glob).
Activity
martindurant commentedon Oct 7, 2020
Sorry about this, a case of choosing one optimisation over another.
#360 changed
findto not be recursive, so that you can complete the request in a single call for a nested directory tree, becausefindis usually used to get everything. The previous version was usually slower except in the case you have before you, or a small value fordepth.We could resurrect the old code, and use it for the case that depth is small. What do you think?
gerritholl commentedon Oct 7, 2020
I haven't followed the history so it's difficult for me to comment on the optimisation of find (and I don't understand the linked PR; from its diff it looks like the method didn't exist at all before?), but the current situation in which there exists a
max_depthargument that is ignored (even without warning) seems undesirable. I'm not personally using find directly, but ratherfs.glob("noaa-goes16/ABI-L1B-RadF/*")(or a different pattern, but with a single*only), so iffindbecomes too complicated when maintaining two approaches for small or large values of depth, then it would work for me ifglobwith a single*got its listing elsewhere (such as fromls?).gerritholl commentedon Oct 7, 2020
Oops, I just realised that the
globmethod implementation is not ins3fsat all, but inherited froms3fs.AbstractFileSystem. So it would still need to be resolved here (changing the implementation offindseems then more sensible than overloading glob).gerritholl commentedon Oct 7, 2020
I can confirm that in v0.5.0 the MCVE (adding
withdirs=True) works as expected, but in v0.5.1 there is a problem. Slightly longer example:With 0.5.0:
With 0.5.1:
i.e. it's not just trading one optimisation against another, I think we can call this broken.
martindurant commentedon Oct 7, 2020
I would appreciate if you would for this into a (failing) test function with expectations in a PR, so that a fix is easier to make.
martindurant commentedon Oct 7, 2020
Note that with current master, the last result is also 24, so something got fixed along the line.
Test for fsspec#378 to verify find respects maxdepth.
gerritholl commentedon Oct 8, 2020
See #379 for a unit test exposing the problem. I need to focus on something else right now.
Merge pull request #379 from gerritholl/shallow-find