|
19 | 19 | from functools import partial, reduce
|
20 | 20 | import itertools
|
21 | 21 | import operator
|
| 22 | +from packaging.version import Version |
22 | 23 | from typing import TYPE_CHECKING, Any, Optional, TypeGuard
|
23 | 24 | import warnings
|
24 | 25 | from xml.dom.minidom import Document
|
|
60 | 61 | __all__ = ["Cube", "CubeAttrsDict", "CubeList"]
|
61 | 62 |
|
62 | 63 |
|
| 64 | +# Determine the numpy printoptions legacy setting. |
| 65 | +_NP_VERSION = Version(np.__version__) |
| 66 | +_NP_LEGACY_VERSION = Version("2.2") |
| 67 | +NP_PRINTOPTIONS_LEGACY = str(_NP_LEGACY_VERSION) if Version(f"{_NP_VERSION.major}.{_NP_VERSION.minor}") > _NP_LEGACY_VERSION else False |
| 68 | + |
63 | 69 | # The XML namespace to use for CubeML documents
|
64 | 70 | XML_NAMESPACE_URI = "urn:x-iris:cubeml-0.2"
|
65 | 71 |
|
@@ -162,7 +168,7 @@ def insert(self, index, cube):
|
162 | 168 |
|
163 | 169 | def xml(self, checksum=False, order=True, byteorder=True):
|
164 | 170 | """Return a string of the XML that this list of cubes represents."""
|
165 |
| - with np.printoptions(legacy="2.2"): |
| 171 | + with np.printoptions(legacy=NP_PRINTOPTIONS_LEGACY): |
166 | 172 | doc = Document()
|
167 | 173 | cubes_xml_element = doc.createElement("cubes")
|
168 | 174 | cubes_xml_element.setAttribute("xmlns", XML_NAMESPACE_URI)
|
@@ -3865,7 +3871,7 @@ def xml(
|
3865 | 3871 | byteorder: bool = True,
|
3866 | 3872 | ) -> str:
|
3867 | 3873 | """Return a fully valid CubeML string representation of the Cube."""
|
3868 |
| - with np.printoptions(legacy="2.2"): |
| 3874 | + with np.printoptions(legacy=NP_PRINTOPTIONS_LEGACY): |
3869 | 3875 | doc = Document()
|
3870 | 3876 |
|
3871 | 3877 | cube_xml_element = self._xml_element(
|
|
0 commit comments