issues: 2109180364
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2109180364 | I_kwDOAMm_X859t4nM | 8685 | Wrong sum of boolean negation | 4087525 | closed | 0 | 3 | 2024-01-31T02:52:31Z | 2024-01-31T12:58:32Z | 2024-01-31T12:58:32Z | NONE | What happened?I get the wrong answer when I chain boolean negation with sum(). It works when I put parentheses around the negation, or when I first write the negation result to a new variable. See code example. What did you expect to happen?No response Minimal Complete Verifiable Example```Python import numpy as np import xarray as xr data = np.array([True, False, True, False]) test = xr.DataArray(data, coords=dict(x=np.arange(4))) assert np.sum(test) == 2 assert test.sum(dim="x") == 2 assert np.sum(~test) == 2 (~test).sum(dim="x") == 2 tmp = ~test assert tmp.sum(dim="x") == 2 assert ~test.sum(dim="x") == 2, f"not 2: {~test.sum(dim='x').data}" # returns -3 ``` MVCE confirmation
Relevant log output```Python AssertionError Traceback (most recent call last) File example.py:14 12 tmp = ~test 13 assert tmp.sum(dim="x") == 2 ---> 14 assert ~test.sum(dim="x") == 2, f"not 2: {~test.sum(dim='x').data}" # returns -3 AssertionError: not 2: -3 ``` Anything else we need to know?No response Environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:01:35) [Clang 16.0.6 ]
python-bits: 64
OS: Darwin
OS-release: 23.2.0
machine: arm64
processor: arm
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: None
libnetcdf: None
xarray: 2024.1.1
pandas: 2.2.0
numpy: 1.26.3
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 69.0.3
pip: 23.3.2
conda: None
pytest: None
mypy: None
IPython: 8.20.0
sphinx: None
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/8685/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |