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
The difference between filter and search is not intuitive and is unnecessary. Furthermore, the api should be refined to be more clear and provide more error handling
The motivation
I just ran this query and had no idea what happened:
In [1]: archives=api.batch_get_archive(api.search(
... : pattern='ACP/climate/smme/HDD-CDD/county/001/annual/rcp85/*/198101-*.nc')
... :
In [2]: len(archives) # The query took forever, then returned ALL archivesOut[2]: 13375
Turns out the problem was that api.search doesn't have a pattern argument, but since it accepts **kwargs it failed to catch this. The correct query is:
In [3]: archives=api.batch_get_archive(api.filter(
... : pattern='ACP/climate/smme/HDD-CDD/county/001/annual/rcp85/*/198101-*.nc')
... :
In [4]: len(archives)
Out[4]: 44
Proposed solution
We should merge filter and search into one function:
defsearch(self, *query, prefix=None, pattern=None, engine='path'):
''' Search for archives using tags, patterns, and prefixes Parameters --------- query: str tags to search for prefix: str start of archive name. Providing a start string improves search speed. pattern: str string matching the characters within the archive or set of archives you are filtering on. Note that authority prefixes, e.g. ``local://my/archive.txt`` are not supported in pattern searches. engine: str string of value 'str', 'path', or 'regex'. That indicates the type of pattern you are filtering on yields ------ archive_name : str names of archives matching the specified criteria '''ifprefixisnotNone:
prefix=fs.path.relpath(prefix)
ifpatternisnotNone:
pattern=fs.path.relpath(pattern)
archives=self.manager.search(query, begins_with=prefix, )
ifnotpattern:
forarchiveinarchives:
yieldarchiveelifengine=='str':
forarchinarchives:
ifpatterninarch:
yieldarchelifengine=='path':
# Change to generator version of fnmatch.filterforarchinarchives:
iffnmatch.fnmatch(arch, pattern):
yieldarchelifengine=='regex':
forarchinarchives:
ifre.search(pattern, arch):
yieldarchelse:
raiseValueError(
'search engine "{}" not recognized. '.format(engine) +'choose "str", "fn", or "regex"')
The text was updated successfully, but these errors were encountered:
The Issue
The difference between filter and search is not intuitive and is unnecessary. Furthermore, the api should be refined to be more clear and provide more error handling
The motivation
I just ran this query and had no idea what happened:
Turns out the problem was that api.search doesn't have a pattern argument, but since it accepts **kwargs it failed to catch this. The correct query is:
Proposed solution
We should merge filter and search into one function:
The text was updated successfully, but these errors were encountered: