question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poor error message on Dataset.sum(axis=...)

See original GitHub issue

ll_means.nc.gz

MCVE Code Sample

I’m attaching the relevant .nc file.

foo = xr.open_dataset('ll_means.nc')
print(foo)
foo.sum(axis=1) # or foo.sum(axis=0)

Instead of getting a sum (either across the data variables or across the dimension shared between the variables), I get the error in the title: ValueError: cannot supply both 'axis' and 'dim' arguments even though I did not supply a dim argument. Furthermore, I get this error even when passing dim=None.

It’s possible that I am doing something wrong, and it is just the error message that is bad, and not the behavior. I don’t know enough to tell.

Expected Output

TBQH, I didn’t know whether this would sum across the (single) dimension of this dataset, or if it would sum across the data variables along that dimension. I was experimenting to try to figure this out.

What I am trying to do is sum across the data variables, “perpendicular” to a dimension, instead of along it.

Problem Description

I assumed that summing across one of the axes would sum across the data variables, but perhaps that was a bad assumption. At any rate, the current behavior is undesirable.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.4 (default, Jul 9 2019, 18:13:23) [Clang 10.0.1 (clang-1001.0.46.4)] python-bits: 64 OS: Darwin OS-release: 18.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.2 libnetcdf: 4.6.3

xarray: 0.12.3 pandas: 0.25.1 numpy: 1.17.1 scipy: 1.3.1 netCDF4: 1.5.2 pydap: None h5netcdf: None h5py: 2.9.0 Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.1.1 cartopy: None seaborn: 0.9.0 numbagg: None setuptools: 41.2.0 pip: 19.3.1 conda: None pytest: None IPython: 7.8.0 sphinx: None

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
crusaderkycommented, Oct 29, 2019

I think there’s space here to make xarray more user friendly. A better error message would particularly be useful with new xarray users which are used to numpy and pandas - which is the most common new user profile TBH.

0reactions
max-sixtycommented, Oct 29, 2019

OK, good points

Read more comments on GitHub >

github_iconTop Results From Across the Web

error handling; pandas and data analysis
f-strings are a convenient way to construct error messages: anything inside curly brackets is interpreted as a Python expression. e.g.
Read more >
Finding the mean of nuisance columns in DataFrame error
Using numeric_only=True causes df.mean() to ignore columns that contain non-numbers, and only calculate the mean for columns that only contain ...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
Error: Measures with Looker aggregations (sum, average, min ...
SQL statements such as this generate a double or nested aggregation in SQL — most SQL dialects are unable to double aggregate, or...
Read more >
Data Cleaning with Python and Pandas: Detecting Missing ...
Data was lost while transferring manually from a legacy database. There was a programming error. Users chose not to fill out a field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found