Skip to content

Commit

Permalink
unpin cftime (#4222)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle authored Jul 22, 2021
1 parent c61d5e5 commit dd91f04
Show file tree
Hide file tree
Showing 22 changed files with 296 additions and 514 deletions.
16 changes: 6 additions & 10 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ iris_test_data_template: &IRIS_TEST_DATA_TEMPLATE
#
# Linting
#
lint_task:
task:
only_if: ${SKIP_LINT_TASK} == ""
<< : *CREDITS_TEMPLATE
auto_cancellation: true
Expand All @@ -133,12 +133,10 @@ lint_task:
#
# Testing Minimal (Linux)
#
test_minimal_task:
task:
only_if: ${SKIP_TEST_MINIMAL_TASK} == "" && ${SKIP_ALL_TEST_TASKS} == ""
<< : *CREDITS_TEMPLATE
matrix:
env:
PY_VER: 3.6
env:
PY_VER: 3.7
env:
Expand All @@ -155,12 +153,10 @@ test_minimal_task:
#
# Testing Full (Linux)
#
test_full_task:
task:
only_if: ${SKIP_TEST_FULL_TASK} == "" && ${SKIP_ALL_TEST_TASKS} == ""
<< : *CREDITS_TEMPLATE
matrix:
env:
PY_VER: 3.6
env:
PY_VER: 3.7
env:
Expand All @@ -183,7 +179,7 @@ test_full_task:
#
# Testing Documentation Gallery (Linux)
#
gallery_task:
task:
only_if: ${SKIP_GALLERY_TASK} == "" && ${SKIP_ALL_DOC_TASKS} == ""
<< : *CREDITS_TEMPLATE
env:
Expand All @@ -202,7 +198,7 @@ gallery_task:
#
# Testing Documentation (Linux)
#
doctest_task:
task:
only_if: ${SKIP_DOCTEST_TASK} == "" && ${SKIP_ALL_DOC_TASKS} == ""
<< : *CREDITS_TEMPLATE
env:
Expand All @@ -226,7 +222,7 @@ doctest_task:
#
# Testing Documentation Link Check (Linux)
#
linkcheck_task:
task:
only_if: ${SKIP_LINKCHECK_TASK} == "" && ${SKIP_ALL_DOC_TASKS} == ""
<< : *CREDITS_TEMPLATE
env:
Expand Down
20 changes: 17 additions & 3 deletions docs/iris/src/whatsnew/3.0.4.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. include:: ../common_links.inc

v3.0.4 (?? ??August 2021)
*************************
v3.0.4 (22 July 2021)
*********************

This document explains the changes made to Iris for this release
(:doc:`View all changes <index>`.)
Expand All @@ -22,7 +22,18 @@ This document explains the changes made to Iris for this release
Firstly, ancillary-variables or cell-measures with long names can now widen the cube "dimensions map" to fit,
whereas previously printing these cases caused an Exception.
Secondly, cube units are now always printed, whereas previously they were missed out any time that the
"dimensions map" was widened to accomodate long coordinate names. (:pull:`4233`)
"dimensions map" was widened to accomodate long coordinate names.
(:pull:`4233`)(:pull:`4238`)

💼 **Internal**

#. `@bjlittle`_ Unpinned the `cftime`_ package dependency within Iris in order
to allow use of the latest versions of `cftime`_, `cf-units`_ and `nc-time-axis`_.
(:pull:`4222`)

Note that, we are forced to drop support for ``Python 3.6`` in this patch due to
the third-party package dependencies required by (:pull:`4222`).


.. dropdown:: :opticon:`alert` v3.0.3 Patches
:container: + shadow
Expand Down Expand Up @@ -600,3 +611,6 @@ This document explains the changes made to Iris for this release
.. _travis-ci: https://travis-ci.org/github/SciTools/iris
.. _stickler-ci: https://stickler-ci.com/
.. _@jamesp: https://github.com/jamesp
.. _cftime: https://github.com/Unidata/cftime
.. _cf-units: https://github.com/SciTools/cf-units
.. _nc-time-axis: https://github.com/SciTools/nc-time-axis
2 changes: 1 addition & 1 deletion lib/iris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def callback(cube, field, filename):


# Iris revision.
__version__ = "3.0.3"
__version__ = "3.0.4"

# Restrict the names imported when using "from iris import *"
__all__ = [
Expand Down
8 changes: 4 additions & 4 deletions lib/iris/fileformats/name_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def _generate_cubes(
coord_units = _parse_units("FL")
if coord.name == "time":
coord_units = time_unit
pts = time_unit.date2num(coord.values)
pts = np.float_(time_unit.date2num(coord.values))

if coord.dimension is not None:
if coord.name == "longitude":
Expand All @@ -507,7 +507,7 @@ def _generate_cubes(
):
dt = coord.values - field_headings["Av or Int period"]
bnds = time_unit.date2num(np.vstack((dt, coord.values)).T)
icoord.bounds = bnds
icoord.bounds = np.float_(bnds)
else:
icoord.guess_bounds()
cube.add_dim_coord(icoord, coord.dimension)
Expand All @@ -524,7 +524,7 @@ def _generate_cubes(
):
dt = coord.values - field_headings["Av or Int period"]
bnds = time_unit.date2num(np.vstack((dt, coord.values)).T)
icoord.bounds = bnds[i, :]
icoord.bounds = np.float_(bnds[i, :])
cube.add_aux_coord(icoord)

# Headings/column headings which are encoded elsewhere.
Expand Down Expand Up @@ -1252,7 +1252,7 @@ def load_NAMEIII_trajectory(filename):

long_name = units = None
if isinstance(values[0], datetime.datetime):
values = time_unit.date2num(values)
values = np.float_(time_unit.date2num(values))
units = time_unit
if name == "Time":
name = "time"
Expand Down
36 changes: 34 additions & 2 deletions lib/iris/fileformats/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,8 +1476,18 @@ def t1(self):
"""
if not hasattr(self, "_t1"):
has_year_zero = self.lbyr == 0
calendar = (
None if self.lbmon == 0 or self.lbdat == 0 else self.calendar
)
self._t1 = cftime.datetime(
self.lbyr, self.lbmon, self.lbdat, self.lbhr, self.lbmin
self.lbyr,
self.lbmon,
self.lbdat,
self.lbhr,
self.lbmin,
calendar=calendar,
has_year_zero=has_year_zero,
)
return self._t1

Expand All @@ -1500,8 +1510,18 @@ def t2(self):
"""
if not hasattr(self, "_t2"):
has_year_zero = self.lbyrd == 0
calendar = (
None if self.lbmond == 0 or self.lbdatd == 0 else self.calendar
)
self._t2 = cftime.datetime(
self.lbyrd, self.lbmond, self.lbdatd, self.lbhrd, self.lbmind
self.lbyrd,
self.lbmond,
self.lbdatd,
self.lbhrd,
self.lbmind,
calendar=calendar,
has_year_zero=has_year_zero,
)
return self._t2

Expand Down Expand Up @@ -1537,13 +1557,19 @@ def t1(self):
"""
if not hasattr(self, "_t1"):
has_year_zero = self.lbyr == 0
calendar = (
None if self.lbmon == 0 or self.lbdat == 0 else self.calendar
)
self._t1 = cftime.datetime(
self.lbyr,
self.lbmon,
self.lbdat,
self.lbhr,
self.lbmin,
self.lbsec,
calendar=calendar,
has_year_zero=has_year_zero,
)
return self._t1

Expand All @@ -1566,13 +1592,19 @@ def t2(self):
"""
if not hasattr(self, "_t2"):
has_year_zero = self.lbyrd == 0
calendar = (
None if self.lbmond == 0 or self.lbdatd == 0 else self.calendar
)
self._t2 = cftime.datetime(
self.lbyrd,
self.lbmond,
self.lbdatd,
self.lbhrd,
self.lbmind,
self.lbsecd,
calendar=calendar,
has_year_zero=has_year_zero,
)
return self._t2

Expand Down
2 changes: 1 addition & 1 deletion lib/iris/fileformats/pp_save_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _general_time_rules(cube, pp):
pp.lbtim.ia = 0
pp.lbtim.ib = 0
pp.t1 = time_coord.units.num2date(time_coord.points[0])
pp.t2 = cftime.datetime(0, 0, 0)
pp.t2 = cftime.datetime(0, 0, 0, calendar=None, has_year_zero=True)

# Forecast.
if (
Expand Down
3 changes: 2 additions & 1 deletion lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ def _fixup_dates(coord, values):

r = [
nc_time_axis.CalendarDateTime(
cftime.datetime(*date), coord.units.calendar
cftime.datetime(*date, calendar=coord.units.calendar),
coord.units.calendar,
)
for date in dates
]
Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/integration/plot/test_netcdftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_360_day_calendar(self):
atime.hour,
atime.minute,
atime.second,
calendar=calendar,
)
for atime in times
]
Expand Down
6 changes: 4 additions & 2 deletions lib/iris/tests/test_pp_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ def test_lbtim_access(self):
self.assertEqual(self.r[0].lbtim.ic, 2)

def test_t1_t2_access(self):
field = self.r[0]
calander = "360_day"
self.assertEqual(
self.r[0].t1.timetuple(),
cftime.datetime(1994, 12, 1, 0, 0).timetuple(),
field.t1.timetuple(),
cftime.datetime(1994, 12, 1, 0, 0, calendar=calander).timetuple(),
)

def test_save_single(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/unit/fileformats/pp/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_t2_time_mean(self):

def test_t2_no_time_mean(self):
cube = _get_single_time_cube(set_time_mean=False)
expected = cftime.datetime(0, 0, 0)
expected = cftime.datetime(0, 0, 0, calendar=None, has_year_zero=True)

with mock.patch(
"iris.fileformats.pp.PPField3", autospec=True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# importing anything else.
import iris.tests as tests

from cf_units import Unit, CALENDAR_GREGORIAN
from cf_units import Unit, CALENDAR_GREGORIAN, CALENDAR_360_DAY
from cftime import datetime as nc_datetime
import numpy as np
import unittest
Expand Down Expand Up @@ -47,7 +47,9 @@ class TestLBTIMx0x_SingleTimepoint(TestField):
def _check_timepoint(self, lbcode, expect_match=True):
lbtim = _lbtim(ib=0, ic=1)
t1 = nc_datetime(1970, 1, 1, hour=6, minute=0, second=0)
t2 = nc_datetime(0, 0, 0) # not used in result
t2 = nc_datetime(
0, 0, 0, calendar=None, has_year_zero=True
) # not used in result
lbft = None # unused
coords_and_dims = _convert_time_coords(
lbcode=lbcode,
Expand Down Expand Up @@ -296,8 +298,8 @@ def test_time_cross_section(self):
class TestLBTIMx2x_ZeroYear(TestField):
def test_(self):
lbtim = _lbtim(ib=2, ic=1)
t1 = nc_datetime(0, 1, 1)
t2 = nc_datetime(0, 1, 31, 23, 59, 00)
t1 = nc_datetime(0, 1, 1, has_year_zero=True)
t2 = nc_datetime(0, 1, 31, 23, 59, 00, has_year_zero=True)
lbft = 0
lbcode = _lbcode(1)
coords_and_dims = _convert_time_coords(
Expand All @@ -314,8 +316,8 @@ def test_(self):
class TestLBTIMxxx_Unhandled(TestField):
def test_unrecognised(self):
lbtim = _lbtim(ib=4, ic=1)
t1 = nc_datetime(0, 0, 0)
t2 = nc_datetime(0, 0, 0)
t1 = nc_datetime(0, 0, 0, calendar=None, has_year_zero=True)
t2 = nc_datetime(0, 0, 0, calendar=None, has_year_zero=True)
lbft = None
lbcode = _lbcode(0)
coords_and_dims = _convert_time_coords(
Expand All @@ -333,8 +335,13 @@ class TestLBCODE3xx(TestField):
def test(self):
lbcode = _lbcode(value=31323)
lbtim = _lbtim(ib=2, ic=2)
t1 = nc_datetime(1970, 1, 3, hour=0, minute=0, second=0)
t2 = nc_datetime(1970, 1, 4, hour=0, minute=0, second=0)
calendar = CALENDAR_360_DAY
t1 = nc_datetime(
1970, 1, 3, hour=0, minute=0, second=0, calendar=calendar
)
t2 = nc_datetime(
1970, 1, 4, hour=0, minute=0, second=0, calendar=calendar
)
lbft = 24 * 4
coords_and_dims = _convert_time_coords(
lbcode=lbcode,
Expand Down
Loading

0 comments on commit dd91f04

Please sign in to comment.