Skip to content

Simplify signature of xr.open_dataset using new decoding_kwargs dict #9379

Closed

Description

@TomNicholas

What is your issue?

The signature of xr.open_dataset is quite complicated, but many of the kwargs are really just immediately passed on to the public xr.decode_cf function internally. Specifically mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, and drop_variables are all passed on. Whether or not xr.decode_cf is used at all is controlled by the decode_cf kwarg, which is currently a boolean.

We could instead group all of these kwargs into a single decoding_kwargs dictionary keyword argument. We could also replace the decode_cf kwarg with a general decode or decode_func kwarg, with a type something like Callable[Dataset | AbstractDataStore, Dataset], which by default would point to the xr.decode_cf function.

This would:

  • Greatly simplify the signature of xr.open_dataset,
  • More clearly separate concerns (opening data and decoding are separate steps),
  • Allow users to define their own decoding functions, even with existing backends (e.g. a netCDF file that follows non-CF conventions, such as can be found in plasma physics),
  • Follow the same pattern we already use in open_dataset for from_array_kwargs and backend_kwargs,
  • Avoid this old issue Can we clarify decode_cf option of open_dataset? #3020 (because once the deprecation cycle was complete you wouldn't be able to pass a specific decoding kwarg whilst also specifying that no decoding is to happen).

The downside of this is that there would be a fairly significant blast radius of warnings raised during the deprecation cycle.

Activity

  1. dcherian commented on Aug 19, 2024

    @dcherian
    Contributor

    Cam we close in favor of #4490?

  2. TomNicholas commented on Aug 19, 2024

    @TomNicholas
    MemberAuthor

    Cam we close in favor of #4490?

    Oops 🤦‍♂️ I'll add anything not already mentioned there then close this.

  3. TomNicholas commented on Aug 19, 2024

    @TomNicholas
    MemberAuthor

    Closing as a duplicate, see #4490 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions