From e2638fffeda67a4a7ec5a2057a180256342f600f Mon Sep 17 00:00:00 2001 From: jswhit Date: Sat, 6 Jul 2024 11:57:13 -0600 Subject: [PATCH 01/13] expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions). --- .github/workflows/cibuildwheel.yml | 2 +- include/netCDF4.pxi | 1 + src/netCDF4/__init__.py | 4 +-- src/netCDF4/_netCDF4.pyx | 43 +++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index e7d515be7..da4c1365c 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -60,7 +60,7 @@ jobs: - os: macos-14 arch: arm64 CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=14.0 - - os: macos-11 + - os: macos-13 arch: x86_64 CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=11.0 diff --git a/include/netCDF4.pxi b/include/netCDF4.pxi index 9404171db..f748bf82c 100644 --- a/include/netCDF4.pxi +++ b/include/netCDF4.pxi @@ -392,6 +392,7 @@ cdef extern from "netcdf-compat.h": int nc_set_alignment(int threshold, int alignment) int nc_get_alignment(int *threshold, int *alignment) int nc_rc_set(char* key, char* value) nogil + const_char_ptr *nc_rc_get(char* key) int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp) nogil int nc_create_mem(const char *path, int mode, size_t initialize, int *ncidp) nogil diff --git a/src/netCDF4/__init__.py b/src/netCDF4/__init__.py index ac93047a2..e63ad3fc6 100644 --- a/src/netCDF4/__init__.py +++ b/src/netCDF4/__init__.py @@ -10,10 +10,10 @@ __has_parallel4_support__, __has_pnetcdf_support__, __has_quantization_support__, __has_zstandard_support__, __has_bzip2_support__, __has_blosc_support__, __has_szip_support__, - __has_set_alignment__) + __has_set_alignment__, __has_nc_rc_set__) import os __all__ =\ -['Dataset','Variable','Dimension','Group','MFDataset','MFTime','CompoundType','VLType','date2num','num2date','date2index','stringtochar','chartostring','stringtoarr','getlibversion','EnumType','get_chunk_cache','set_chunk_cache','set_alignment','get_alignment'] +['Dataset','Variable','Dimension','Group','MFDataset','MFTime','CompoundType','VLType','date2num','num2date','date2index','stringtochar','chartostring','stringtoarr','getlibversion','EnumType','get_chunk_cache','set_chunk_cache','set_alignment','get_alignment','nc_get','nc_set'] __pdoc__ = { 'utils': False, } diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 49f62ee5c..269ea733e 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -1308,15 +1308,56 @@ __has_blosc_support__ = HAS_BLOSC_SUPPORT __has_szip_support__ = HAS_SZIP_SUPPORT __has_set_alignment__ = HAS_SET_ALIGNMENT __has_ncfilter__ = HAS_NCFILTER +__has_nc_rc_set__ = HAS_NCRCSET # set path to SSL certificates (issue #1246) # available starting in version 4.9.1 -if HAS_NCRCSET: +if __has_nc_rc_set__: import certifi if nc_rc_set("HTTP.SSL.CAINFO", _strencode(certifi.where())) != 0: raise RuntimeError('error setting path to SSL certificates') +def rc_get(key): + """ +**`rc_key(key)`** + +Returns the internal netcdf-c rc table value corresponding to key. + """ + cdef int ierr + cdef char *keyc + if __has_nc_rc_set__: + bytestr = _strencode(_tostr(key)) + keyc = bytestr + return (nc_rc_get(keyc)).decode('utf-8') + else: + raise RuntimeError( + "This function requires netcdf4 4.9.0+ to be used at compile time" + ) + +def rc_set(key, value): + """ +**`rc_set(key, value)`** + +Sets the internal netcdf-c rc table value corresponding to key. + """ + cdef int ierr + cdef char *keyc + cdef char *valuec + if __has_nc_rc_set__: + key_bytestr = _strencode(_tostr(key)) + keyc = key_bytestr + val_bytestr = _strencode(_tostr(value)) + valuec = val_bytestr + with nogil: + ierr = nc_rc_set(keyc,valuec) + _ensure_nc_success(ierr) + else: + raise RuntimeError( + "This function requires netcdf4 4.9.0+ to be used at compile time" + ) + + # check for required version of netcdf-4 and hdf5. def _gethdf5libversion(): From 7a715110e0040a1555ff62e81b8832a915a0b476 Mon Sep 17 00:00:00 2001 From: jswhit Date: Sat, 6 Jul 2024 12:08:39 -0600 Subject: [PATCH 02/13] update --- src/netCDF4/_netCDF4.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 269ea733e..c740e114c 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -1332,7 +1332,7 @@ Returns the internal netcdf-c rc table value corresponding to key. return (nc_rc_get(keyc)).decode('utf-8') else: raise RuntimeError( - "This function requires netcdf4 4.9.0+ to be used at compile time" + "This function requires netcdf-c 4.9.0+ to be used at compile time" ) def rc_set(key, value): @@ -1354,7 +1354,7 @@ Sets the internal netcdf-c rc table value corresponding to key. _ensure_nc_success(ierr) else: raise RuntimeError( - "This function requires netcdf4 4.9.0+ to be used at compile time" + "This function requires netcdf-c 4.9.0+ to be used at compile time" ) @@ -1435,7 +1435,7 @@ def get_alignment(): if not __has_set_alignment__: raise RuntimeError( - "This function requires netcdf4 4.9.0+ to be used at compile time" + "This function requires netcdf-c 4.9.0+ to be used at compile time" ) cdef int ierr @@ -1458,7 +1458,7 @@ def set_alignment(threshold, alignment): if not __has_set_alignment__: raise RuntimeError( - "This function requires netcdf4 4.9.0+ to be used at compile time" + "This function requires netcdf-c 4.9.0+ to be used at compile time" ) cdef int ierr From eb4fcf068bf45ed700c77332da6ed0c39fccf127 Mon Sep 17 00:00:00 2001 From: jswhit Date: Sat, 6 Jul 2024 13:40:25 -0600 Subject: [PATCH 03/13] add test --- .github/workflows/cibuildwheel.yml | 4 ++-- include/netcdf-compat.h | 1 + test/test_ncrc.py | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/test_ncrc.py diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index da4c1365c..b6415474f 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -60,9 +60,9 @@ jobs: - os: macos-14 arch: arm64 CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=14.0 - - os: macos-13 + - os: macos-12 arch: x86_64 - CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=11.0 + CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=12.0 steps: - uses: actions/checkout@v4 diff --git a/include/netcdf-compat.h b/include/netcdf-compat.h index 89e7b20fe..b445d6922 100644 --- a/include/netcdf-compat.h +++ b/include/netcdf-compat.h @@ -60,6 +60,7 @@ static inline int nc_get_alignment(int* thresholdp, int* alignmentp) { #else #define HAS_NCRCSET 0 static inline int nc_rc_set(const char* key, const char* value) { return NC_EINVAL; } +static inline const char *nc_rc_set(const char* key) { return NC_EINVAL; } #endif #if NC_VERSION_GE(4, 4, 0) diff --git a/test/test_ncrc.py b/test/test_ncrc.py new file mode 100644 index 000000000..ece9c94f3 --- /dev/null +++ b/test/test_ncrc.py @@ -0,0 +1,17 @@ +import unittest +import netCDF4 + +class NCRCTestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + def runTest(self): + """testing access of data over http using opendap""" + netCDF4.rc_set('foo','bar') + assert netCDF4.rc_get('foo') == 'bar' + +if __name__ == '__main__': + unittest.main() From c2074caec2b75c88b902db6fb6ab7b3135d1171d Mon Sep 17 00:00:00 2001 From: jswhit Date: Sat, 6 Jul 2024 13:44:46 -0600 Subject: [PATCH 04/13] update --- test/test_ncrc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/test_ncrc.py b/test/test_ncrc.py index ece9c94f3..508a36227 100644 --- a/test/test_ncrc.py +++ b/test/test_ncrc.py @@ -1,5 +1,6 @@ import unittest import netCDF4 +from netCDF4 import __has_nc_rc_set__ class NCRCTestCase(unittest.TestCase): def setUp(self): @@ -9,9 +10,10 @@ def tearDown(self): pass def runTest(self): - """testing access of data over http using opendap""" - netCDF4.rc_set('foo','bar') - assert netCDF4.rc_get('foo') == 'bar' + """test rc_get, rc_set functions""" + if __has_nc_rc_set__: + netCDF4.rc_set('foo','bar') + assert netCDF4.rc_get('foo') == 'bar' if __name__ == '__main__': unittest.main() From 6ce9f48e631424264f385f4cd9fa758f23b478b4 Mon Sep 17 00:00:00 2001 From: jswhit Date: Sat, 6 Jul 2024 13:56:32 -0600 Subject: [PATCH 05/13] fix typo --- include/netcdf-compat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/netcdf-compat.h b/include/netcdf-compat.h index b445d6922..d1144d979 100644 --- a/include/netcdf-compat.h +++ b/include/netcdf-compat.h @@ -60,7 +60,7 @@ static inline int nc_get_alignment(int* thresholdp, int* alignmentp) { #else #define HAS_NCRCSET 0 static inline int nc_rc_set(const char* key, const char* value) { return NC_EINVAL; } -static inline const char *nc_rc_set(const char* key) { return NC_EINVAL; } +static inline const char *nc_rc_get(const char* key) { return NC_EINVAL; } #endif #if NC_VERSION_GE(4, 4, 0) From 74c4f379adb65afa947acbb3dae669bbdead290b Mon Sep 17 00:00:00 2001 From: jswhit Date: Mon, 8 Jul 2024 11:15:30 -0600 Subject: [PATCH 06/13] add new functions to stub --- Changelog | 2 +- src/netCDF4/__init__.pyi | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 1b1157406..d4c5011f6 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,4 @@ - version 1.7.2 (tag v1.7.2rel) + version 1.7.2 (not yet released) =============================== * add static type hints (PR #1302) diff --git a/src/netCDF4/__init__.pyi b/src/netCDF4/__init__.pyi index 413336f0e..61ea2aa10 100644 --- a/src/netCDF4/__init__.pyi +++ b/src/netCDF4/__init__.pyi @@ -14,7 +14,7 @@ __all__ = [ 'Dataset', 'Variable', 'Dimension', 'Group', 'MFDataset', 'MFTime', 'CompoundType', 'VLType', 'date2num', 'num2date', 'date2index', 'stringtochar', 'chartostring', 'stringtoarr', 'getlibversion', 'EnumType', 'get_chunk_cache', 'set_chunk_cache', - 'set_alignment', 'get_alignment' + 'set_alignment', 'get_alignment', 'nc_get', 'nc_set', ] __pdoc__ = {'utils': False} @@ -87,6 +87,7 @@ __has_blosc_support__: BoolInt __has_szip_support__: BoolInt __has_set_alignment__: BoolInt __has_ncfilter__: BoolInt +__has_nc_rc_set__: BoolInt is_native_little: bool is_native_big: bool default_encoding: Final = 'utf-8' @@ -624,6 +625,8 @@ def chartostring( ) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ... def getlibversion() -> str: ... +def nc_get(key: str) -> str: ... +def nc_set(key: str, val: str): ... def set_alignment(threshold: int, alignment: int): ... def get_alignment() -> tuple[int, int]: ... From 4e4488c1d11a76c5fc63fa335e6eaf5793f5f6d7 Mon Sep 17 00:00:00 2001 From: jswhit Date: Mon, 8 Jul 2024 12:43:09 -0600 Subject: [PATCH 07/13] fixes for failing stubtest --- Changelog | 1 + src/netCDF4/__init__.py | 2 +- src/netCDF4/__init__.pyi | 6 +++--- src/netCDF4/_netCDF4.pyi | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index d4c5011f6..f1e82e2b3 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ version 1.7.2 (not yet released) =============================== * add static type hints (PR #1302) + * Expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions). (PR #1348) version 1.7.1 (tag v1.7.1rel) =============================== diff --git a/src/netCDF4/__init__.py b/src/netCDF4/__init__.py index b14015254..e7e94d2cf 100644 --- a/src/netCDF4/__init__.py +++ b/src/netCDF4/__init__.py @@ -16,7 +16,7 @@ 'Dataset', 'Variable', 'Dimension', 'Group', 'MFDataset', 'MFTime', 'CompoundType', 'VLType', 'date2num', 'num2date', 'date2index', 'stringtochar', 'chartostring', 'stringtoarr', 'getlibversion', 'EnumType', 'get_chunk_cache', 'set_chunk_cache', - 'set_alignment', 'get_alignment', 'nc_get', 'nc_set', + 'set_alignment', 'get_alignment', 'rc_get', 'rc_set', ] __pdoc__ = {'utils': False} # if HDF5_PLUGIN_PATH not set, point to package path if plugins live there diff --git a/src/netCDF4/__init__.pyi b/src/netCDF4/__init__.pyi index 61ea2aa10..fd9fb8957 100644 --- a/src/netCDF4/__init__.pyi +++ b/src/netCDF4/__init__.pyi @@ -14,7 +14,7 @@ __all__ = [ 'Dataset', 'Variable', 'Dimension', 'Group', 'MFDataset', 'MFTime', 'CompoundType', 'VLType', 'date2num', 'num2date', 'date2index', 'stringtochar', 'chartostring', 'stringtoarr', 'getlibversion', 'EnumType', 'get_chunk_cache', 'set_chunk_cache', - 'set_alignment', 'get_alignment', 'nc_get', 'nc_set', + 'set_alignment', 'get_alignment', 'rc_get', 'rc_set', ] __pdoc__ = {'utils': False} @@ -625,8 +625,8 @@ def chartostring( ) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ... def getlibversion() -> str: ... -def nc_get(key: str) -> str: ... -def nc_set(key: str, val: str): ... +def rc_get(key: str) -> str: ... +def rc_set(key: str, val: str)-> None: ... def set_alignment(threshold: int, alignment: int): ... def get_alignment() -> tuple[int, int]: ... diff --git a/src/netCDF4/_netCDF4.pyi b/src/netCDF4/_netCDF4.pyi index 536d4f63b..304e50e69 100644 --- a/src/netCDF4/_netCDF4.pyi +++ b/src/netCDF4/_netCDF4.pyi @@ -6,13 +6,14 @@ from . import ( stringtoarr, getlibversion, EnumType, get_chunk_cache, set_chunk_cache, set_alignment, get_alignment, default_fillvals, default_encoding, NetCDF4MissingFeatureException, is_native_big, is_native_little, unicode_error, + rc_get, rc_set, __version__, __netcdf4libversion__, __hdf5libversion__, __has_rename_grp__, __has_nc_inq_path__, __has_nc_inq_format_extended__, __has_nc_open_mem__, __has_nc_create_mem__, __has_cdf5_format__, __has_parallel4_support__, __has_pnetcdf_support__, __has_parallel_support__, __has_quantization_support__, __has_zstandard_support__, __has_bzip2_support__, __has_blosc_support__, __has_szip_support__, - __has_set_alignment__, __has_ncfilter__ + __has_set_alignment__, __has_ncfilter__, __has_nc_rc_set__, ) From 28814f8a89df8d2929e4c0928eded20dd9aa3909 Mon Sep 17 00:00:00 2001 From: jswhit Date: Mon, 8 Jul 2024 14:00:21 -0600 Subject: [PATCH 08/13] fix stub for rc_set --- src/netCDF4/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netCDF4/__init__.pyi b/src/netCDF4/__init__.pyi index fd9fb8957..062384f01 100644 --- a/src/netCDF4/__init__.pyi +++ b/src/netCDF4/__init__.pyi @@ -626,7 +626,7 @@ def chartostring( def getlibversion() -> str: ... def rc_get(key: str) -> str: ... -def rc_set(key: str, val: str)-> None: ... +def rc_set(key: str, value: str)-> None: ... def set_alignment(threshold: int, alignment: int): ... def get_alignment() -> tuple[int, int]: ... From ab3e123f491949b0528b92f82aab0bff2bc9196a Mon Sep 17 00:00:00 2001 From: jswhit Date: Mon, 8 Jul 2024 21:16:49 -0600 Subject: [PATCH 09/13] bump version number --- src/netCDF4/_netCDF4.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index c5431e8f3..97ecfe3e3 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -1,4 +1,4 @@ -"""Version 1.7.1 +"""Version 1.7.2 ------------- # Introduction @@ -1272,7 +1272,7 @@ import sys import functools from typing import Union -__version__ = "1.7.1.post1" +__version__ = "1.7.2" # Initialize numpy import posixpath From c85e7cf0236274506534e4956c322af5b972f677 Mon Sep 17 00:00:00 2001 From: jswhit Date: Tue, 9 Jul 2024 10:07:04 -0600 Subject: [PATCH 10/13] fix docstring formatting --- src/netCDF4/_netCDF4.pyx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 97ecfe3e3..ae1cca64e 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -1320,7 +1320,7 @@ if __has_nc_rc_set__: def rc_get(key): """ -**`rc_key(key)`** +**```rc_get(key)```** Returns the internal netcdf-c rc table value corresponding to key. """ @@ -1337,7 +1337,7 @@ Returns the internal netcdf-c rc table value corresponding to key. def rc_set(key, value): """ -**`rc_set(key, value)`** +**```rc_set(key, value)```** Sets the internal netcdf-c rc table value corresponding to key. """ @@ -1371,7 +1371,7 @@ def _gethdf5libversion(): def getlibversion(): """ -**`getlibversion()`** +**```getlibversion()```** returns a string describing the version of the netcdf library used to build the module, and when it was built. @@ -1380,7 +1380,7 @@ used to build the module, and when it was built. def get_chunk_cache(): """ -**`get_chunk_cache()`** +**```get_chunk_cache()```** return current netCDF chunk cache information in a tuple (size,nelems,preemption). See netcdf C library documentation for `nc_get_chunk_cache` for @@ -1396,7 +1396,7 @@ details. Values can be reset with `set_chunk_cache`.""" def set_chunk_cache(size=None,nelems=None,preemption=None): """ -**`set_chunk_cache(self,size=None,nelems=None,preemption=None)`** +**```set_chunk_cache(size=None,nelems=None,preemption=None)```** change netCDF4 chunk cache settings. See netcdf C library documentation for `nc_set_chunk_cache` for @@ -1424,7 +1424,7 @@ details.""" def get_alignment(): - """**`get_alignment()`** + """**```get_alignment()```** return current netCDF alignment within HDF5 files in a tuple (threshold,alignment). See netcdf C library documentation for @@ -1448,7 +1448,7 @@ def get_alignment(): def set_alignment(threshold, alignment): - """**`set_alignment(threshold,alignment)`** + """**```set_alignment(threshold,alignment)```** Change the HDF5 file alignment. See netcdf C library documentation for `nc_set_alignment` for From b60aee061a871e7b7e412a3b8cd667e3dda31a9a Mon Sep 17 00:00:00 2001 From: jswhit Date: Tue, 9 Jul 2024 10:08:58 -0600 Subject: [PATCH 11/13] update docs --- docs/index.html | 126 +++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 54 deletions(-) diff --git a/docs/index.html b/docs/index.html index 6971ceb5b..730c955d7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,19 +2,22 @@ - - + + netCDF4 API documentation - - - - - - + + + + + + - - + +
@@ -23,7 +26,7 @@

Package netCDF4

-

Version 1.7.0

+

Version 1.7.2

Introduction

netcdf4-python is a Python interface to the netCDF C library.

netCDF version 4 has many features @@ -118,8 +121,8 @@

Creating/Opening/Closing a netCDF If the file is open for write access (mode='w', 'r+' or 'a'), you may write any type of data including new dimensions, groups, variables and attributes. -netCDF files come in five flavors (NETCDF3_CLASSIC, -NETCDF3_64BIT_OFFSET, NETCDF3_64BIT_DATA, NETCDF4_CLASSIC<code>, and </code>NETCDF4). +netCDF files come in five flavors (NETCDF3_CLASSIC, +NETCDF3_64BIT_OFFSET, NETCDF3_64BIT_DATA, NETCDF4_CLASSIC, and NETCDF4). NETCDF3_CLASSIC was the original netcdf binary format, and was limited to file sizes less than 2 Gb. NETCDF3_64BIT_OFFSET was introduced in version 3.6.0 of the library, and extended the original binary format @@ -1261,7 +1264,7 @@

Functions

def get_alignment()
-

get_alignment()

+

get_alignment()

return current netCDF alignment within HDF5 files in a tuple (threshold,alignment). See netcdf C library documentation for nc_get_alignment for details. Values can be reset with @@ -1272,7 +1275,7 @@

Functions

def get_chunk_cache()
-

get_chunk_cache()

+

get_chunk_cache()

return current netCDF chunk cache information in a tuple (size,nelems,preemption). See netcdf C library documentation for nc_get_chunk_cache for details. Values can be reset with set_chunk_cache().

@@ -1281,7 +1284,7 @@

Functions

def getlibversion()
-

getlibversion()

+

getlibversion()

returns a string describing the version of the netcdf library used to build the module, and when it was built.

@@ -1340,11 +1343,25 @@

Functions

do not contain a time-zone offset, even if the specified units contains one.

+
+def rc_get(key) +
+
+

rc_get(key)

+

Returns the internal netcdf-c rc table value corresponding to key.

+
+
+def rc_set(key, value) +
+
+

rc_set(key, value)

+

Sets the internal netcdf-c rc table value corresponding to key.

+
def set_alignment(threshold, alignment)
-

set_alignment()(threshold,alignment)

+

set_alignment(threshold,alignment)

Change the HDF5 file alignment. See netcdf C library documentation for nc_set_alignment for details.

@@ -1354,7 +1371,7 @@

Functions

def set_chunk_cache(size=None, nelems=None, preemption=None)
-

set_chunk_cache(self,size=None,nelems=None,preemption=None)

+

set_chunk_cache(size=None,nelems=None,preemption=None)

change netCDF4 chunk cache settings. See netcdf C library documentation for nc_set_chunk_cache for details.

@@ -1415,12 +1432,12 @@

Classes

the user.

__init__(group, datatype, datatype_name)

CompoundType constructor.

-

group: Group instance to associate with the compound datatype.

-

datatype: A numpy dtype object describing a structured (a.k.a record) +

grp: Group instance to associate with the compound datatype.

+

dt: A numpy dtype object describing a structured (a.k.a record) array. Can be composed of homogeneous numeric or character data types, or other structured array data types.

-

datatype_name: a Python string containing a description of the +

dtype_name: a Python string containing a description of the compound data type.

Note 1: When creating nested compound data types, the inner compound data types must already be associated with CompoundType @@ -1433,15 +1450,15 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var dtype_view
-

Return an attribute of instance, which is of type owner.

+
var name
-

Return an attribute of instance, which is of type owner.

+
@@ -1623,39 +1640,39 @@

Instance variables

var auto_complex
-

Return an attribute of instance, which is of type owner.

+
var cmptypes
-

Return an attribute of instance, which is of type owner.

+
var data_model
-

Return an attribute of instance, which is of type owner.

+
var dimensions
-

Return an attribute of instance, which is of type owner.

+
var disk_format
-

Return an attribute of instance, which is of type owner.

+
var enumtypes
-

Return an attribute of instance, which is of type owner.

+
var file_format
-

Return an attribute of instance, which is of type owner.

+
var groups
-

Return an attribute of instance, which is of type owner.

+
var keepweakref
-

Return an attribute of instance, which is of type owner.

+
var name
@@ -1663,19 +1680,19 @@

Instance variables

var parent
-

Return an attribute of instance, which is of type owner.

+
var path
-

Return an attribute of instance, which is of type owner.

+
var variables
-

Return an attribute of instance, which is of type owner.

+
var vltypes
-

Return an attribute of instance, which is of type owner.

+

Methods

@@ -2264,15 +2281,15 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var enum_dict
-

Return an attribute of instance, which is of type owner.

+
var name
-

Return an attribute of instance, which is of type owner.

+
@@ -2476,11 +2493,11 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var name
-

Return an attribute of instance, which is of type owner.

+
@@ -2668,15 +2685,15 @@

Instance variables

var always_mask
-

Return an attribute of instance, which is of type owner.

+
var auto_complex
-

Return an attribute of instance, which is of type owner.

+
var chartostring
-

Return an attribute of instance, which is of type owner.

+
var datatype
@@ -2691,11 +2708,11 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var mask
-

Return an attribute of instance, which is of type owner.

+
var name
@@ -2703,11 +2720,11 @@

Instance variables

var ndim
-

Return an attribute of instance, which is of type owner.

+
var scale
-

Return an attribute of instance, which is of type owner.

+
var shape
@@ -3049,10 +3066,9 @@

Methods

- \ No newline at end of file + From 6d399a92039062c82003645b7f92b422d037a5bf Mon Sep 17 00:00:00 2001 From: jswhit Date: Tue, 9 Jul 2024 10:42:49 -0600 Subject: [PATCH 12/13] check for NULL pointer from nc_rc_get --- src/netCDF4/__init__.pyi | 2 +- src/netCDF4/_netCDF4.pyx | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/netCDF4/__init__.pyi b/src/netCDF4/__init__.pyi index 062384f01..1a709dd35 100644 --- a/src/netCDF4/__init__.pyi +++ b/src/netCDF4/__init__.pyi @@ -625,7 +625,7 @@ def chartostring( ) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ... def getlibversion() -> str: ... -def rc_get(key: str) -> str: ... +def rc_get(key: str) -> str | None: ... def rc_set(key: str, value: str)-> None: ... def set_alignment(threshold: int, alignment: int): ... diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index ae1cca64e..b912cdfb6 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -1326,10 +1326,15 @@ Returns the internal netcdf-c rc table value corresponding to key. """ cdef int ierr cdef char *keyc + cdef char *valc if __has_nc_rc_set__: bytestr = _strencode(_tostr(key)) keyc = bytestr - return (nc_rc_get(keyc)).decode('utf-8') + valc = nc_rc_get(keyc) + if valc is NULL: + return None + else: + return valc.decode('utf-8') else: raise RuntimeError( "This function requires netcdf-c 4.9.0+ to be used at compile time" From 180584a6c1dcb9cb692730e8a2600463601c1de0 Mon Sep 17 00:00:00 2001 From: jswhit Date: Tue, 9 Jul 2024 10:43:31 -0600 Subject: [PATCH 13/13] update test --- test/test_ncrc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_ncrc.py b/test/test_ncrc.py index 508a36227..02cd168c4 100644 --- a/test/test_ncrc.py +++ b/test/test_ncrc.py @@ -14,6 +14,7 @@ def runTest(self): if __has_nc_rc_set__: netCDF4.rc_set('foo','bar') assert netCDF4.rc_get('foo') == 'bar' + assert netCDF4.rc_get('bar') == None if __name__ == '__main__': unittest.main()