Skip to content

Extend unary operations to apply to bounds #147

@davidhassell

Description

@davidhassell

Currently, unary operation do not apply to bounds, but equivalent binary operations do:

>>> f = cf.example_field(0)
>>> a = f.dimension_coordinate('X')
>>> a.bounds.array
array([[  0.,  45.],
       [ 45.,  90.],
       [ 90., 135.],
       [135., 180.],
       [180., 225.],
       [225., 270.],
       [270., 315.],
       [315., 360.]])
b = -1 * a
>>> b.bounds.array
array([[  -0.,  -45.],
       [ -45.,  -90.],
       [ -90., -135.],
       [-135., -180.],
       [-180., -225.],
       [-225., -270.],
       [-270., -315.],
       [-315., -360.]])
>>> c = -a
>>> c.bounds.array 
array([[  0.,  45.],
       [ 45.,  90.],
       [ 90., 135.],
       [135., 180.],
       [180., 225.],
       [225., 270.],
       [270., 315.],
       [315., 360.]])

This is inconsistent. I propose making the arithmetic (as opposed to bitwise) unary operators also apply to bounds, when present, i.e. __abs__, __neg__, and __pos__ only.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions