Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ version 3.17.0
* Fix bug that caused `Data._axes` to be incorrect after a call to
`cf.Field.collapse`
(https://github.com/NCAS-CMS/cf-python/issues/857)
* Fix bug that caused wrong directions from
`cf.DimensionCoordinate.direction`
(https://github.com/NCAS-CMS/cf-python/issues/859)
* Changed dependency: ``Python>=3.9.0``
* Changed dependency: ``numpy>=2.0.0``
* Changed dependency: ``cfdm>=1.12.0.0, <1.12.1.0``
Expand Down
14 changes: 7 additions & 7 deletions cf/dimensioncoordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def _infer_direction(self):
"""Return True if a coordinate is increasing, otherwise return
False.

A dimension coordinate construct is considered to be increasing if
its data array values are increasing in index space, or if it has
no data nor bounds.
A dimension coordinate construct is considered to be
increasing if its data array values are not strictly
decreasing in index space, or if it has no data nor bounds.

If the direction can not be inferred from the data not bounds then
the coordinate's units are used.
Expand Down Expand Up @@ -168,12 +168,12 @@ def _infer_direction(self):
c = data._get_cached_elements()
if c:
try:
return bool(c.get(0) < c.get(1))
return bool(c.get(0) <= c.get(1))
except TypeError:
pass

data = data[:2].compute()
return bool(data.item(0) < data.item(1))
return bool(data.item(0) <= data.item(1))

# Still here?
data = self.get_bounds_data(None, _fill_value=False)
Expand All @@ -182,12 +182,12 @@ def _infer_direction(self):
c = data._get_cached_elements()
if c:
try:
return bool(c.get(0) < c.get(1))
return bool(c.get(0) <= c.get(1))
except TypeError:
pass

b = data[0].compute()
return bool(b.item(0) < b.item(1))
return bool(b.item(0) <= b.item(1))

# Still here? Then infer the direction from the units.
return not self.Units.ispressure
Expand Down