Skip to content

Commit 8135fcc

Browse files
authored
Merge pull request #292 from davidhassell/cfdump-format
Python 3.12 compatability
2 parents 3a76bfc + 59ad5b3 commit 8135fcc

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

Changelog.rst

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version NEXTRELEASE
2+
-------------------
3+
4+
**2024-??-??**
5+
6+
* Upgrades to allow cfdm to work with Python 3.12
7+
(https://github.com/NCAS-CMS/cfdm/issues/302)
8+
9+
----
10+
111
Version 1.11.1.0
212
----------------
313

cfdm/data/data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def __int__(self):
395395
f"Python scalars. Got {self}"
396396
)
397397

398-
return int(self.array)
398+
return int(self.array[(0,) * self.ndim])
399399

400400
def __iter__(self):
401401
"""Called when an iterator is required.

cfdm/read_write/netcdf/netcdfread.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ def read(
10251025

10261026
# If the string contains any commas, it is assumed to be a
10271027
# comma-separated list.
1028-
all_conventions = re.split(",\s*", Conventions)
1028+
all_conventions = re.split(r",\s*", Conventions)
10291029
if all_conventions[0] == Conventions:
10301030
all_conventions = Conventions.split()
10311031

cfdm/read_write/netcdf/netcdfwrite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3949,7 +3949,7 @@ def _write_field_or_domain(
39493949
# Ancillary variables
39503950
if field and ancillary_variables:
39513951
ancillary_variables = " ".join(ancillary_variables)
3952-
ancillary_variables = re.sub("\s+", " ", ancillary_variables)
3952+
ancillary_variables = re.sub(r"\s+", " ", ancillary_variables)
39533953
logger.info(
39543954
" Writing ancillary_variables attribute to "
39553955
f"netCDF variable {ncvar}: {ancillary_variables!r}"

cfdm/test/test_Data.py

+9
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,15 @@ def test_Data_masked_values(self):
784784
self.assertTrue(np.isclose(da, a).all())
785785
self.assertTrue((da.mask == a.mask).all())
786786

787+
def test_Data__int__(self):
788+
"""Test Data.__int__."""
789+
for x in (1.1, [1.1], [[1.1]]):
790+
self.assertEqual(int(cfdm.Data(x)), 1)
791+
792+
# Can't int on data with size > 1
793+
with self.assertRaises(TypeError):
794+
int(cfdm.Data([1, 2]))
795+
787796

788797
if __name__ == "__main__":
789798
print("Run date:", datetime.datetime.now())

scripts/cfdump

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ if __name__ == "__main__":
1111
def print_help(version, date):
1212
import subprocess
1313

14-
manpage = """\
14+
manpage = """
1515
.TH "CFDUMP" "1" "{0}" "{1}" "cfdump"
1616
.
1717
.SH NAME
1818
.
19-
cfdump \- view the contents of a CF-netCDF dataset according to the CF data model.
19+
cfdump - view the contents of a CF-netCDF dataset according to the CF data model.
2020
.
2121
.
2222
.
2323
.SH SYNOPSIS
2424
.
25-
cfdump [\-s] [\-c] [\-e file [\-e file] ...] [\-h] file
25+
cfdump [-s] [-c] [-e file [-e file] ...] [-h] file
2626
.
2727
.
2828
.
@@ -49,32 +49,32 @@ For versions of the CF conventions up to and including CF-{3}.
4949
.SH OPTIONS
5050
.
5151
.TP
52-
.B \-c, \-\-complete
52+
.B -c, --complete
5353
Display complete descriptions. All properties of all constructs,
5454
including metadata constructs and their components are described
5555
without abbreviation with the exception of data arrays which are
5656
generally abbreviated to their first and last values.
5757
.
5858
.
5959
.TP
60-
.B \-e file, \-\-external=file
60+
.B -e file, --external=file
6161
Read external variables from the given external file. Multiple
6262
external files may be provided by specifying more than one
6363
.ft B
64-
\-e
64+
-e
6565
.ft P
6666
option.
6767
.
6868
.
6969
.TP
70-
.B \-h, \-\-help
70+
.B -h, --help
7171
Display this man page.
7272
.
7373
.
7474
.TP
75-
.B \-s, \-\-short
75+
.B -s, --short
7676
Display short descriptions. Each field construct is described by a
77-
short, one\-line summary that gives the identity of the field
77+
short, one-line summary that gives the identity of the field
7878
construct; the identities and sizes of the dimensions spanned by the
7979
data array; and the units of the data.
8080
.
@@ -105,7 +105,7 @@ David Hassell
105105
[
106106
"man",
107107
"-r",
108-
" Manual page cfdump(1)\ ?ltline\ %lt?L/%L.:",
108+
" Manual page cfdump(1) ?ltline %lt?L/%L.:",
109109
"-l",
110110
"-",
111111
],

0 commit comments

Comments
 (0)