Skip to content

unhashable type: 'numpy.ndarray' if 'units' attribute is numpy array in NetCDF file #6367

Closed
@okhoma

Description

@okhoma

What happened?

Calling load_dataset() for a file with variable with the 'units' attribute being numpy.ndarray as following:

{'paramId': array([3015], dtype=int64), 
'typeOfLevel': 'heightAboveGround', 
'gridType': 'regular_ll', 
'bottomLevel': array([2], dtype=int64), 
'cfVarName': 'tmax', 
'missingValue': array([9999], dtype=int64), 
'name': 'Maximum temperature', 
'scaledValueOfFirstFixedSurface': array([2], dtype=int64), 
'scaledValueOfSecondFixedSurface': array([0], dtype=int64), 
'shortName': 'tmax', 
'topLevel': array([2], dtype=int64), 
'units': array(['˚C'], dtype=object), 
'max': array(['47.22 ˚C'], dtype=object), 
'min': array(['-59.20 ˚C'], dtype=object), 
'comment': 'Daily max'}

Causes error "unhashable type: 'numpy.ndarray'"

if "units" in attrs and attrs["units"] in TIME_UNITS:
, because attrs['units'] is a numpy.ndarray.

What did you expect to happen?

I guess another check could be added to ignore the attribute if its value is unhashable

Minimal Complete Verifiable Example

No response

Relevant log output

No response

Anything else we need to know?

No response

Environment

xr.show_versions()
INSTALLED VERSIONS

commit: None
python: 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 22:01:29) [MSC v.1900 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: (None, None)
libhdf5: 1.10.6
libnetcdf: 4.7.4
xarray: 0.19.0
pandas: 1.3.2
numpy: 1.21.5
scipy: 1.6.0
netCDF4: 1.5.6
pydap: None
h5netcdf: 0.11.0
h5py: 3.2.1
Nio: None
zarr: None
cftime: 1.5.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.1.7
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.5.1
cartopy: 0.18.0
seaborn: None
numbagg: None
pint: None
setuptools: 59.8.0
pip: 21.0.1
conda: None
pytest: 6.2.5
IPython: None
sphinx: 4.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triageIssue that has not been reviewed by xarray team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions