Skip to content

Commit 160b219

Browse files
committed
Migrate to pycdfpp>=0.6
Signed-off-by: Alexis Jeandet <[email protected]>
1 parent 2bab5e8 commit 160b219

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

pyistp/_impl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _get_attributes(cdf: object, var: str):
1919
value = cdf.variable_attribute_value(var, attr)
2020
if attr.endswith("_PTR") or attr[:-1].endswith("_PTR_"):
2121
if cdf.has_variable(value):
22-
value = cdf.values(value)
22+
value = cdf.values(value, is_metadata_variable=True)
2323
if hasattr(value, 'tolist'):
2424
attrs[attr] = value.tolist()
2525
else:

pyistp/drivers/pycdfpp.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
import pycdfpp
2+
import numpy as np
3+
4+
5+
def _drop_first_dim_if_nrv(is_nrv: bool, values):
6+
if is_nrv:
7+
if values.shape[0] == 1:
8+
return values[0]
9+
else:
10+
return np.array([], dtype=values.dtype)
11+
else:
12+
return values
213

314

415
class Driver:
@@ -24,7 +35,7 @@ def has_variable(self, name):
2435
return name in self.cdf
2536

2637
def is_char(self, var):
27-
return self.cdf[var].type == pycdfpp.CDF_CHAR
38+
return self.cdf[var].type == pycdfpp.DataType.CDF_CHAR
2839

2940
def variable_attributes(self, var):
3041
if self.cdf:
@@ -36,8 +47,10 @@ def variable_attribute_value(self, var, attr):
3647
return self.cdf[var].attributes[attr][0]
3748
return None
3849

39-
def values(self, var):
40-
v = self.cdf[var]
41-
if v.type in (pycdfpp.CDF_EPOCH, pycdfpp.CDF_EPOCH16, pycdfpp.CDF_TIME_TT2000):
42-
return pycdfpp.to_datetime64(v)
43-
return v.values
50+
def values(self, var, is_metadata_variable=False):
51+
v: pycdfpp.Variable = self.cdf[var]
52+
if v.type in (pycdfpp.DataType.CDF_EPOCH, pycdfpp.DataType.CDF_EPOCH16, pycdfpp.DataType.CDF_TIME_TT2000):
53+
return _drop_first_dim_if_nrv(v.is_nrv, pycdfpp.to_datetime64(v))
54+
if is_metadata_variable and self.is_char(var):
55+
return _drop_first_dim_if_nrv(v.is_nrv, v.values_encoded)
56+
return _drop_first_dim_if_nrv(v.is_nrv, v.values)

pyistp/drivers/spacepy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def variable_attribute_value(self, var, attr):
4444
return self.cdf[var].attrs[attr]
4545
return None
4646

47-
def values(self, var):
47+
def values(self, var, is_metadata_variable=False):
4848
v = self.cdf[var]
4949
if v.type() in (pycdf.const.CDF_EPOCH, pycdf.const.CDF_EPOCH16, pycdf.const.CDF_TIME_TT2000):
5050
return np.vectorize(np.datetime64)(v[:])

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ classifiers = [
2828
"Programming Language :: Python :: 3.9",
2929
"Programming Language :: Python :: 3.10",
3030
"Programming Language :: Python :: 3.11",
31+
"Programming Language :: Python :: 3.12",
3132
]
32-
dependencies = ['pycdfpp<=0.4.6']
33+
dependencies = ['pycdfpp>=0.6.0']
3334
[project.urls]
3435
homepage = "https://github.com/SciQLop/PyISTP"
3536
repository = "https://github.com/SciQLop/PyISTP"

requirements_dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pycdfpp
1+
pycdfpp>=0.6.0
22
pip
33
bump2version
44
wheel

0 commit comments

Comments
 (0)