You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a field has a construct which can have data, e.g. a coordinate, but that construct doesn't have data, the str() representation hits a ValueError regarding the lack of data on that construct, e.g:
>>> f = cf.example_fields()
>>> u = f[2]
>>> print(u)
Field: air_potential_temperature (ncvar%air_potential_temperature)
------------------------------------------------------------------
Data : air_potential_temperature(time(36), latitude(5), longitude(8)) K
Cell methods : area: mean
Dimension coords: time(36) = [1959-12-16 12:00:00, ..., 1962-11-16 00:00:00]
: latitude(5) = [-75.0, ..., 75.0] degrees_north
: longitude(8) = [22.5, ..., 337.5] degrees_east
: air_pressure(1) = [850.0] hPa
>>>
>>> u.get_construct('dimensioncoordinate0').del_data() # delete data from a coordinate
<CF Data(36): [1959-12-16 12:00:00, ..., 1962-11-16 00:00:00]>
>>> u # the repr is still available to view
<CF Field: air_potential_temperature(time(36), latitude(5), longitude(8)) K>
>>> print(u) # but now try to print the field out...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfdm/field.py", line 241, in __str__
string.append(str(self.domain))
File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfdm/domain.py", line 194, in __str__
y = f"{name}({dim.get_data().size})"
File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cf/mixin/propertiesdata.py", line 4919, in get_data
return super().get_data(
File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfdm/core/abstract/propertiesdata.py", line 292, in get_data
return self._default(
File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfdm/core/abstract/container.py", line 147, in _default
raise default
ValueError: DimensionCoordinate has no data
(note the repr() still works). Whilst the error is logically correct, I feel it is not appropriate to be raised in the case of an object string representation, where it would be much more useful to display the usual output but with some indicator that there is no data for a given construct, perhaps something as simple as [] in place of the missing data, or a dedicated marker such as <no data>, e.g. for the example above:
When a field has a construct which can have data, e.g. a coordinate, but that construct doesn't have data, the
str()
representation hits aValueError
regarding the lack of data on that construct, e.g:(note the
repr()
still works). Whilst the error is logically correct, I feel it is not appropriate to be raised in the case of an object string representation, where it would be much more useful to display the usual output but with some indicator that there is no data for a given construct, perhaps something as simple as[]
in place of the missing data, or a dedicated marker such as<no data>
, e.g. for the example above:>>> print(u) Field: air_potential_temperature (ncvar%air_potential_temperature) ------------------------------------------------------------------ Data : air_potential_temperature(time(36), latitude(5), longitude(8)) K Cell methods : area: mean Dimension coords: time(time(36)) = [] : latitude(5) = [-75.0, ..., 75.0] degrees_north : longitude(8) = [22.5, ..., 337.5] degrees_east : air_pressure(1) = [850.0] hPa
@davidhassell what do you think? (It may even be that the issue described is a bug?)
Interestingly, if instead of deleting the data on
u
, we set it to[None]
, I see the following:which may also be a bug...
The text was updated successfully, but these errors were encountered: