Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit handling in xarray fails for Python 3.12 #205

Open
crdanielbusch opened this issue Apr 2, 2024 · 0 comments
Open

Unit handling in xarray fails for Python 3.12 #205

crdanielbusch opened this issue Apr 2, 2024 · 0 comments

Comments

@crdanielbusch
Copy link
Collaborator

crdanielbusch commented Apr 2, 2024

Describe the bug

The function pr.sum removes the units in a dataset for Python version 3.12.2

Failing Test

github_issue_ds_1.csv

import primap2 as pm

test_data = pm.open_dataset("github_issue_ds_1.csv")

test_data = test_data.pr.sum(dim="category", skipna=True, min_count=1)

print(test_data.pr.to_interchange_format()['unit'])

Output for Python 3.10.13:

0      CH4 * gigagram / a
1       CO * gigagram / a
2      CO2 * gigagram / a
3      N2O * gigagram / a
4    NMVOC * gigagram / a
5      NOx * gigagram / a
6      SO2 * gigagram / a
Name: unit, dtype: object

Output for Python 3.12.2:

/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
/Users/danielbusch/Documents/UNFCCC_non-AnnexI_data/venv/lib/python3.12/site-packages/xarray/namedarray/core.py:215: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return NamedArray(dims, np.asarray(data), attrs)
0    no unit
1    no unit
2    no unit
3    no unit
4    no unit
5    no unit
6    no unit
Name: unit, dtype: object

Expected behavior

The sum function should calculate the sum over the given dimension and keep all the unit information.

System (please complete the following information):

  • OS: [macOS]
  • Python version 3.12.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant