fsspec / fsspec/kerchunk

Add `xarray.open_dataset` backend

Open
#360 8 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
366
Forks
96
Avg merge
24m
Merged PRs (30d)
1

Description

https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html describes how to add a new backend to xarray's open_dataset. Adding a backend will make it easier for users to consume kerchunk references.

Here's a prototype:

from xarray.backends import BackendEntrypoint


class KerchunkBackendEntrypoint(BackendEntrypoint):
    def open_dataset(
        self,
        filename_or_obj,
        *,
        drop_variables=None,
        **kwargs,
    ):
        return my_open_dataset(filename_or_obj, drop_variables=drop_variables, **kwargs)

    open_dataset_parameters = ["filename_or_obj", "drop_variables"]

    def guess_can_open(self, filename_or_obj):
        try:
            _, ext = os.path.splitext(filename_or_obj)
        except TypeError:
            return False
        return ext in {".json", ".parquet"}

    description = "Use Kerchunk files in Xarray"
    url = "https://fsspec.github.io/kerchunk/"

def my_open_dataset(filename_or_obj, drop_variables, **kwargs):
    m = fsspec.filesystem("reference", fo=filename_or_obj, **kwargs).get_mapper()
    return xr.open_dataset(m, engine="zarr", consolidated=False)

This would be usable like

ds = xr.open_dataset(refs, engine="kerchunk")
ds

This came up at https://discourse.pangeo.io/t/making-kerchunk-as-simple-as-a-toggle/3690.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read xarray's how-to-add-new-backend guide and the prototype built around xarray.backends.BackendEntrypoint. Start from the xarray.open_dataset(..., engine="kerchunk") entry point and determine how the kerchunk reference formats are recognized and opened. Done means the backend is usable through that API for the described references, with appropriate project coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.