Repository navigation
Unconverted NetCDF4Array in Dask compute after collapse #856
Description
Activity
- changed the title
[-]Unconverted `NetCDF4Array` erroring during Dask `compute` after collapse[/-][+]Unconverted `NetCDF4Array` during Dask `compute` after collapse[/+]on Mar 28, 2025 - changed the title
[-]Unconverted `NetCDF4Array` during Dask `compute` after collapse[/-][+]Unconverted `NetCDF4Array` during Dask `compute` post-collapse[/+]on Mar 28, 2025 - changed the title
[-]Unconverted `NetCDF4Array` during Dask `compute` post-collapse[/-][+]Unconverted `NetCDF4Array` in Dask `compute` after collapse[/+]on Mar 28, 2025 Fixed by using cfdm v1.12.1.0, which includes the PR NCAS-CMS/cfdm#333. I.e. the MRE works as expected in this case.
(We need to change the cfdm pin to
cfdm>=1.12.1.0,<1.12.2.0before releasing3.17.0)Reacted by Sadie L. Bartholomewsadielbartholomew commented
on Mar 31, 2025 MemberAuthorMore actionsWas just going to add because I forgot to add this on Friday, but in case it provides clues, here's the
pdboutput of inspection on the__dict__of a collapse that doesn't run into the errort_mamand the one that does,t_djf:(Pdb) t_djf.data.__dict__ {'_Units_class': <class 'cf.units.Units'>, '_components': {'custom': {'has_deterministic_name': True}, 'units': 'hours since 1900-01-01 00:00:00.0', 'calendar': 'gregorian', 'dask': dask.array<concatenate, shape=(44,), dtype=float64, chunksize=(1,), chunktype=numpy.ndarray>, '__in_memory__': False, 'Units': <Units: hours since 1900-01-01 00:00:00.0 gregorian>, 'axes': ('dim0',), 'hardmask': True, '__keepdims_indexing__': True, '__orthogonal_indexing__': True, 'netcdf': {'aggregation_fragment_type': 'location'}, 'original_filenames': ('/home/slb93/recipes/ERA5_monthly_averaged_SST.nc',), 'cached_elements': {0: array(1077456, dtype=int32)}}} (Pdb) t_mam.data.__dict__ {'_Units_class': <class 'cf.units.Units'>, '_components': {'custom': {'has_deterministic_name': True}, 'units': 'hours since 1900-01-01 00:00:00.0', 'calendar': 'gregorian', 'dask': dask.array<concatenate, shape=(43,), dtype=float64, chunksize=(1,), chunktype=numpy.ndarray>, '__in_memory__': False, 'Units': <Units: hours since 1900-01-01 00:00:00.0 gregorian>, 'axes': ('dim1', 'dim0'), 'hardmask': True, '__keepdims_indexing__': True, '__orthogonal_indexing__': True, 'netcdf': {'aggregation_fragment_type': 'location', 'aggregated_data': {}}, 'original_filenames': ('/home/slb93/recipes/ERA5_monthly_averaged_SST.nc',)}}
Of notable differences, the erroring one has cached elements and just one axis not two.
sadielbartholomew commented
on Mar 31, 2025 MemberAuthorMore actionsI think possibly the issue arises because the cached element needs to be converted to a consistent data type, or checked for this consistency? Anyway, we don't have to worry too much with the PR fix to cover all cases.
Hmm. I wonder why
t_mam.datahas two axes. I'm going to have a look at that.Reacted by Sadie L. BartholomewMore Hmm. Why is
t_mamincreasing:array([ 703428., 712188., 720948., 729708., 738492., 747252., 756012., 764772., 773556., 782316., 791076., 799836., 808620., 817380., 826140., 834900., 843684., 852444., 861204., 869964., 878748., 887508., 896268., 905028., 913812., 922572., 931332., 940092., 948876., 957636., 966396., 975156., 983940., 992700., 1001460., 1010220., 1019004., 1027764., 1036524., 1045284., 1054068., 1062828., 1071588.])
but
t_djfdecreasing:array([1077456., 1069440., 1060680., 1051896., 1043136., 1034376., 1025616., 1016832., 1008072., 999312., 990552., 981768., 973008., 964248., 955488., 946704., 937944., 929184., 920424., 911640., 902880., 894120., 885360., 876576., 867816., 859056., 850296., 841512., 832752., 823992., 815232., 806448., 797688., 788928., 780168., 771384., 762624., 753864., 745104., 736320., 727560., 718800., 710040., 701628.])
Weird? The only change I made in the MRE was switching
cf.djfandcf.mam.Reacted by Sadie L. BartholomewOK - the
_axesthings is an unrelated bug (issue to follow!), which I don't think is upsetting Dask.Reacted by Sadie L. Bartholomewsadielbartholomew commented
on Mar 31, 2025 MemberAuthorMore actionsI do hate noticing a bug and in the debugging process, noticing more 😬 But they do tend to congregate, as they say. Thanks for the report.
OK - the _axes things is an unrelated bug (issue to follow!), which I don't think is upsetting Dask.
Reacted by Sadie L. BartholomewResolved by the upstream fix NCAS-CMS/cfdm#331, so closing.
After (at least) doing a grouped collapse whereby the time axis boundaries lie within the group (see MRE below) and attempting to access the underlying data array, an error is raised due to, ultimately, expecting an object of form of a
numpy-like array during the Daskcomputeoperation but encountering acf.NetCDF4Arrayobject, notably:AttributeError: 'NetCDF4Array' object has no attribute 'astype'. Did you mean: 'dtype'.Note I have done some
pdbdebugging on this (just getting the MRE was a quite tricky), which I will also summarise below in a follow-on comment, which implies that aconcatenateoperation may be involved as a prereq for the bug to emerge. I will also investigate the Dask task graph, but am yet to do so due to attending an all-day meeting today and other release-related concerns yesterday.Traceback and field context
See the end for the error report, but it is useful to note the form of the field and affected coordinate hence the
dumpandprintin the MRE below. It produces the following output:MRE
Using an environment from
cf.environment(paths=False)as printed below - in short, using the latestmainbranch forcfdmand for `cf-python:Note if the group to collapse on is changed to another season e.g.
cf.mamorcf.son, the error does not appear! Thesstfield has time data starting in Jan and ending in Dec, therefore it is likely that the fact the time boundaries lie within thedjfseason is related to the problem emerging.Environment, as tested on