pydata / pydata/xarray

Passing keyword arguments to external functions

Open
#7,130 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

design question needs discussion
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What is your issue?

Follow on from #6891 and #6978 to discuss how we could homogenize the passing of keyword arguments to wrapped external functions across xarray methods.

There are quite a few methods like this where we are ultimately passing data to numpy, scipy, or some other library and want the option to send variable length kwargs to that underlying function. There are two different ways of doing this today:

  1. xarray method accepts flexible **kwargs so these can be written directly in the xarray call
  2. xarray method accepts a single dict kwargs (sometimes named differently) and passes these along in expanded form via **kwargs

I could only find a few examples of the latter:

  • Dataset.interp, which takes kwargs
  • Dataset.curvefit, which takes kwargs (although the docstring is wrong here)
  • xr.apply_ufunc, which takes kwargs passed to func and dask_gufunc_kwargs passed to dask.array.apply_gufunc
  • xr.open_dataset, which takes either **kwargs or backend_kwargs and merges the two

Allowing direct passage with **kwargs seems nice from a user perspective. But, this could occasionally be problematic, for example in the Dataset.interp case where this method also accepts the kwarg form of coords with **coords_kwargs. There are many methods like this that use **indexers_kwargs or **chunks_kwargs with either_dict_or_kwargs but don't happen to wrap external functions.

Contributor guide

Open the contributing guide

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

Start by comparing the keyword-argument patterns described for Dataset.interp, Dataset.curvefit, xr.apply_ufunc, and xr.open_dataset, including their interactions with coordinate and backend keyword arguments. Done requires an agreed, consistent API approach across wrapped external functions, with the affected methods and documentation identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
api, data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.