Skip to content

Commit 85f6c8b

Browse files
committed
Fix bug that caused wrong directions from cf.DimensionCoordinate.direction
1 parent 601c14e commit 85f6c8b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ version 3.17.0
1616
* Fix bug that caused `Data._axes` to be incorrect after a call to
1717
`cf.Field.collapse`
1818
(https://github.com/NCAS-CMS/cf-python/issues/857)
19+
* Fix bug that caused wrong directions from
20+
`cf.DimensionCoordinate.direction`
21+
(https://github.com/NCAS-CMS/cf-python/issues/859)
1922
* Changed dependency: ``Python>=3.9.0``
2023
* Changed dependency: ``numpy>=2.0.0``
2124
* Changed dependency: ``cfdm>=1.12.0.0, <1.12.1.0``

cf/dimensioncoordinate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ def _infer_direction(self):
131131
"""Return True if a coordinate is increasing, otherwise return
132132
False.
133133
134-
A dimension coordinate construct is considered to be increasing if
135-
its data array values are increasing in index space, or if it has
136-
no data nor bounds.
134+
A dimension coordinate construct is considered to be
135+
increasing if its data array values are not strictly
136+
decreasing in index space, or if it has no data nor bounds.
137137
138138
If the direction can not be inferred from the data not bounds then
139139
the coordinate's units are used.
@@ -168,12 +168,12 @@ def _infer_direction(self):
168168
c = data._get_cached_elements()
169169
if c:
170170
try:
171-
return bool(c.get(0) < c.get(1))
171+
return bool(c.get(0) <= c.get(1))
172172
except TypeError:
173173
pass
174174

175175
data = data[:2].compute()
176-
return bool(data.item(0) < data.item(1))
176+
return bool(data.item(0) <= data.item(1))
177177

178178
# Still here?
179179
data = self.get_bounds_data(None, _fill_value=False)
@@ -182,12 +182,12 @@ def _infer_direction(self):
182182
c = data._get_cached_elements()
183183
if c:
184184
try:
185-
return bool(c.get(0) < c.get(1))
185+
return bool(c.get(0) <= c.get(1))
186186
except TypeError:
187187
pass
188188

189189
b = data[0].compute()
190-
return bool(b.item(0) < b.item(1))
190+
return bool(b.item(0) <= b.item(1))
191191

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

docs/source/recipes/plot_13_recipe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import cf
2626

27-
2827
# %%
2928
# 2. Read and select the SST by index and look at its contents:
3029
sst = cf.read("~/recipes/ERA5_monthly_averaged_SST.nc")[0]

0 commit comments

Comments
 (0)