diff --git a/Changelog.rst b/Changelog.rst index 301219bae..18d7d85ad 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -1,3 +1,13 @@ +Version NEXTRELEASE +------------------- + +**2024-??-??** + +* Upgrades to allow cfdm to work with Python 3.12 + (https://github.com/NCAS-CMS/cfdm/issues/302) + +---- + Version 1.11.1.0 ---------------- diff --git a/cfdm/data/data.py b/cfdm/data/data.py index 4f3a935d3..e14f7c6cd 100644 --- a/cfdm/data/data.py +++ b/cfdm/data/data.py @@ -395,7 +395,7 @@ def __int__(self): f"Python scalars. Got {self}" ) - return int(self.array) + return int(self.array[(0,) * self.ndim]) def __iter__(self): """Called when an iterator is required. diff --git a/cfdm/read_write/netcdf/netcdfread.py b/cfdm/read_write/netcdf/netcdfread.py index fe43e867c..3deed3445 100644 --- a/cfdm/read_write/netcdf/netcdfread.py +++ b/cfdm/read_write/netcdf/netcdfread.py @@ -1025,7 +1025,7 @@ def read( # If the string contains any commas, it is assumed to be a # comma-separated list. - all_conventions = re.split(",\s*", Conventions) + all_conventions = re.split(r",\s*", Conventions) if all_conventions[0] == Conventions: all_conventions = Conventions.split() diff --git a/cfdm/read_write/netcdf/netcdfwrite.py b/cfdm/read_write/netcdf/netcdfwrite.py index 81190d6ae..daff32731 100644 --- a/cfdm/read_write/netcdf/netcdfwrite.py +++ b/cfdm/read_write/netcdf/netcdfwrite.py @@ -3949,7 +3949,7 @@ def _write_field_or_domain( # Ancillary variables if field and ancillary_variables: ancillary_variables = " ".join(ancillary_variables) - ancillary_variables = re.sub("\s+", " ", ancillary_variables) + ancillary_variables = re.sub(r"\s+", " ", ancillary_variables) logger.info( " Writing ancillary_variables attribute to " f"netCDF variable {ncvar}: {ancillary_variables!r}" diff --git a/cfdm/test/test_Data.py b/cfdm/test/test_Data.py index 639446a2c..13b7fa2f6 100644 --- a/cfdm/test/test_Data.py +++ b/cfdm/test/test_Data.py @@ -784,6 +784,15 @@ def test_Data_masked_values(self): self.assertTrue(np.isclose(da, a).all()) self.assertTrue((da.mask == a.mask).all()) + def test_Data__int__(self): + """Test Data.__int__.""" + for x in (1.1, [1.1], [[1.1]]): + self.assertEqual(int(cfdm.Data(x)), 1) + + # Can't int on data with size > 1 + with self.assertRaises(TypeError): + int(cfdm.Data([1, 2])) + if __name__ == "__main__": print("Run date:", datetime.datetime.now()) diff --git a/scripts/cfdump b/scripts/cfdump index 5ca155c70..df0a5dec7 100755 --- a/scripts/cfdump +++ b/scripts/cfdump @@ -11,18 +11,18 @@ if __name__ == "__main__": def print_help(version, date): import subprocess - manpage = """\ + manpage = """ .TH "CFDUMP" "1" "{0}" "{1}" "cfdump" . .SH NAME . -cfdump \- view the contents of a CF-netCDF dataset according to the CF data model. +cfdump - view the contents of a CF-netCDF dataset according to the CF data model. . . . .SH SYNOPSIS . -cfdump [\-s] [\-c] [\-e file [\-e file] ...] [\-h] file +cfdump [-s] [-c] [-e file [-e file] ...] [-h] file . . . @@ -49,7 +49,7 @@ For versions of the CF conventions up to and including CF-{3}. .SH OPTIONS . .TP -.B \-c, \-\-complete +.B -c, --complete Display complete descriptions. All properties of all constructs, including metadata constructs and their components are described without abbreviation with the exception of data arrays which are @@ -57,24 +57,24 @@ generally abbreviated to their first and last values. . . .TP -.B \-e file, \-\-external=file +.B -e file, --external=file Read external variables from the given external file. Multiple external files may be provided by specifying more than one .ft B -\-e +-e .ft P option. . . .TP -.B \-h, \-\-help +.B -h, --help Display this man page. . . .TP -.B \-s, \-\-short +.B -s, --short Display short descriptions. Each field construct is described by a -short, one\-line summary that gives the identity of the field +short, one-line summary that gives the identity of the field construct; the identities and sizes of the dimensions spanned by the data array; and the units of the data. . @@ -105,7 +105,7 @@ David Hassell [ "man", "-r", - " Manual page cfdump(1)\ ?ltline\ %lt?L/%L.:", + " Manual page cfdump(1) ?ltline %lt?L/%L.:", "-l", "-", ],