pydata / pydata/xarray

DataArray.isin does not accept sets intuitively

Open
#10,022 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What is your issue?

This is halfway between an feature request and a bug report. I do not find the way that DataArray.isin handles sets is very intuitive:

Example:

np_arr = np.arange(5)
dask_arr = da.arange(5)
xr_arr = xr.DataArray(np_arr)
pd_series = pd.Series(np_arr)

s = {1, 2}
print("numpy", np.isin(np_arr, s))
print("dask", da.isin(dask_arr, s).compute())
print("xarray", xr_arr.isin(s))
print("pandas", pd_series.isin(s))

Which results in:

numpy [False False False False False]
dask [False False False False False]
xarray <xarray.DataArray (dim_0: 5)> Size: 5B
array([False, False, False, False, False])
Dimensions without coordinates: dim_0
pandas 0    False
1     True
2     True
3    False
4    False
dtype: bool

Personally, I find only pandas handles this in an intuitive way. But I also understand, that you might want to stay consistent with numpy and dask.

I'd be interested to see what you think!

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 reproducing the DataArray.isin example in the issue and compare its set handling with the shown NumPy, Dask, and pandas results. The issue does not name files or tests, and work is not ready until the desired behavior and consistency decision are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
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.