pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.64k stars 1.09k forks source link

Passing keyword arguments to external functions #7130

Open slevang opened 2 years ago

slevang commented 2 years ago

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:

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.

headtr1ck commented 2 years ago

All plot methods use the **kwargs to pass additional options to matplotlib.

Amisha2778 commented 1 year ago

Hey @headtr1ck I am trying out open source for the first time through Outreachy. Could you please guide me a little so that I could proceed with this issue.

headtr1ck commented 1 year ago

I am trying out open source for the first time through Outreachy. Could you please guide me a little so that I could proceed with this issue.

Welcome to xarray! I think this issue requires some discussion before we can actually address code changes. It would be better to start with a different issue first.