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
The reason for the "dimension_coordinates" alias being an attribute rather than method is that it was expected that it would often be followed by more options:
It turns out that the code for accessing constructs is very slow, and must be improved.
A key part of this improvement relies on being able to work with python dictionaries rather than dictionary-like Constructs objects.
To facilitate this, whilst retaining the intuitive nature of the API (both in cfdm library code and in downstream applications) the least intrusive change is to make what were attributes properties: i.e. f.dimension_coordinates becomes f.dimension_coordinates(). This then allows keyword parameters that can change the behaviour when speed is an issue.
Code breaking
This change will break any code that uses bare construct access attributes:
>>># These won't work any more>>>f.auxiliary_coordinates>>>f.coordinate_references>>>f.coordinates>>>f.cell_measures>>>f.dimension_coordinates>>>f.domain_ancillaries>>>f.domain_axes>>>f.cell_methods>>>f.field_ancillaries
>>># These will work as before>>>f.auxiliary_coordinates()
>>>f.coordinate_references()
>>>f.coordinates()
>>>f.cell_measures()
>>>f.dimension_coordinates()
>>>f.domain_ancillaries()
>>>f.domain_axes()
>>>f.cell_methods()
>>>f.field_ancillaries()
>>># These will also work as before>>>f.auxiliary_coordinates(x)
>>>f.coordinate_references(x)
>>>f.coordinates(x)
>>>f.cell_measures(x)
>>>f.dimension_coordinates(x)
>>>f.domain_ancillaries(x)
>>>f.domain_axes(x)
>>>f.cell_methods(x)
>>>f.field_ancillaries(x)
This is the only backwards incompatible change to the API. All other changes will not break existing code.
With the new API, reading a file is, in one reproducible test, ~10 times faster:
These changes will also make a non-backwards compatible change to the mode parameter of filter_by_axis
Whilst I would still like to do this, this change has the potential for existing to not fail but return wrong answers. Perhaps it needs its issue for maximum visibility?
Whilst I would still like to do this, this change has the potential for existing to not fail but return wrong answers. Perhaps it needs its issue for maximum visibility?
That sounds like a good idea to me. If it could lead to wrong answers with an update it should be highlighted in the Changelog and this would help with that too. 👍
Current situation
Access to named constructs is currently either by the "filter_by_*"
Constructs
methods, or byField
attributes:The reason for the "dimension_coordinates" alias being an attribute rather than method is that it was expected that it would often be followed by more options:
This is fine, but comes with the slight confusion that the result of the attribute is a callable
Constructs
instance, which obfuscates the help:Performance
It turns out that the code for accessing constructs is very slow, and must be improved.
A key part of this improvement relies on being able to work with python dictionaries rather than dictionary-like
Constructs
objects.To facilitate this, whilst retaining the intuitive nature of the API (both in cfdm library code and in downstream applications) the least intrusive change is to make what were attributes properties: i.e.
f.dimension_coordinates
becomesf.dimension_coordinates()
. This then allows keyword parameters that can change the behaviour when speed is an issue.Code breaking
This change will break any code that uses bare construct access attributes:
This is the only backwards incompatible change to the API. All other changes will not break existing code.
With the new API, reading a file is, in one reproducible test, ~10 times faster:
Note that much of the improvement comes from unrelated changes (such as removing unnecessary
__repr__
calls and unnecessary deep copies).PR to follow ...
The text was updated successfully, but these errors were encountered: