Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Search returns same class as self - allowing subclassing #417

Merged
merged 3 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion intake_esm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def search(
.reset_index(drop=True)
)

cat = esm_datastore({'esmcat': self.esmcat.dict(), 'df': esmcat_results})
cat = self.__class__({'esmcat': self.esmcat.dict(), 'df': esmcat_results})
if self.esmcat.has_multiple_variable_assets:
requested_variables = query.get(
self.esmcat.aggregation_control.variable_column_name, []
Expand Down
9 changes: 9 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,12 @@ def funcs(ds):
new_cat.to_dataset_dict(
xarray_open_kwargs={'backend_kwargs': {'storage_options': {'anon': True}}}
)


def test_subclassing_catalog():
class ChildCatalog(intake_esm.esm_datastore):
pass

cat = ChildCatalog(catalog_dict_records)
scat = cat.search(variable=['FOO', 'BAR'])
assert type(scat) is ChildCatalog