Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.12 compatability #292

Merged
merged 8 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
----------------

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

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