-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fsspec.open()
doesn't work with square brackets in a filename
#1476
Comments
fsspec.open uses the same code path as open_files, and allows glob patterns in the string. These are not generally used in filepaths.... So in this case, the
There is probably a way to escape the special characters, but we are laying glob on regex, so I'm not sure how. Also, passing a list containing just the one match (with open_files) doesn't work either, since fsspec also considers a list of glob-strings. |
@martindurant thanks for the quick answer!
Indeed, this is rare. Then I assume the current implementation will remain as is?
Unfortunately me too. |
I'd be happy to find a way through, especially since open() is supposed to work on single paths, never return a list. |
@martindurant Doesn't |
@Skylion007 , you can try, but we are converting from glob-strings to re, and [..] is valid wildcarding in both. |
@martindurant Do we actually want to support globbing in this code path, seems to odd to me to want to do that. Easy solution seems to be use glob.escape and It seems to me like this codepath is designed to work the same as builtins.open so we should probably match call convention. Also, it's not listed anywhere in the doc that |
True, but at the moment, open() calls open_files(...)[0], and the latter does support globbing. It is not totally unreasonable to want to open("file*") and get back the first file that matches, although this is not explicitly documented. |
Besides which, I am not sure that the escaped character would not be caught by the contains_magic checks anyway; and don't forget that they would need to be un-escaped again before passing to the actual backend. |
But it's also totally reasonable to want to get |
@martindurant Figured it out! It was a bug in an arg not being respected in |
For example,
fsspec.open("filename[test].csv")
.Is this by design or a bug? (python builtin
open
function works in this case, at least for python 3.11)The text was updated successfully, but these errors were encountered: