Skip to content

Commit

Permalink
Merge pull request NCAS-CMS#292 from davidhassell/cfdump-format
Browse files Browse the repository at this point in the history
Python 3.12 compatability
davidhassell authored Jun 6, 2024
2 parents 3a76bfc + 59ad5b3 commit 8135fcc
Showing 6 changed files with 32 additions and 13 deletions.
10 changes: 10 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -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
----------------

2 changes: 1 addition & 1 deletion cfdm/data/data.py
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion cfdm/read_write/netcdf/netcdfread.py
Original file line number Diff line number Diff line change
@@ -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()

2 changes: 1 addition & 1 deletion cfdm/read_write/netcdf/netcdfwrite.py
Original file line number Diff line number Diff line change
@@ -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}"
9 changes: 9 additions & 0 deletions cfdm/test/test_Data.py
Original file line number Diff line number Diff line change
@@ -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())
20 changes: 10 additions & 10 deletions scripts/cfdump
Original file line number Diff line number Diff line change
@@ -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,32 +49,32 @@ 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
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",
"-",
],

0 comments on commit 8135fcc

Please sign in to comment.