Skip to content

Commit 39c4f41

Browse files
authored
Merge pull request #39 from Parallel-NetCDF/rename_nc_type
Rename API argument 'nc_dtype' to 'datatype'
2 parents 4f1d279 + 45900c5 commit 39c4f41

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

docs/source/tutorial/basic.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Variables
114114

115115
.. code-block:: Python
116116
117-
var = f.def_var(varname = "var", nc_dtype = pnetcdf.NC_INT, dimensions = ("time", "lat"))
117+
var = f.def_var(varname = "var", datatype = pnetcdf.NC_INT, dimensions = ("time", "lat"))
118118
119119
Equivalent example codes in ``netCDF4-python``:
120120

src/pnetcdf/_File.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,16 @@ cdef class File:
384384
"""
385385
self.rename_dim(oldname, newname)
386386

387-
def def_var(self, varname, nc_dtype, dimensions=(), fill_value=None):
387+
def def_var(self, varname, datatype, dimensions=(), fill_value=None):
388388
"""
389-
def_var(self, varname, nc_dtype, dimensions=(), fill_value=None)
389+
def_var(self, varname, datatype, dimensions=(), fill_value=None)
390390
391391
Create a new variable with the given parameters.
392392
393393
:param varname: Name of the new variable.
394394
:type varname: str
395395
396-
:param nc_dtype: The datatype of the new variable. Supported specifiers are:
396+
:param datatype: The datatype of the new variable. Supported specifiers are:
397397
398398
- ``pnetcdf.NC_CHAR`` for text data
399399
- ``pnetcdf.NC_BYTE`` for 1-byte integer
@@ -410,7 +410,7 @@ cdef class File:
410410
- ``pnetcdf.NC_INT64`` for signed 8-byte integer
411411
- ``pnetcdf.NC_UINT64`` for unsigned 8-byte integer
412412
413-
:type nc_dtype: int
413+
:type datatype: int, str, or numpy.dtype
414414
:param dimensions: [Optional] The dimensions of the new variable. Can be either dimension names
415415
or dimension class instances. Default is an empty tuple which means the variable is a scalar
416416
(and therefore has no dimensions).
@@ -460,17 +460,17 @@ cdef class File:
460460
dimensions =\
461461
tuple(self.dimensions[d] if isinstance(d,(str,bytes)) else d for d in dimensions)
462462
# create variable.
463-
self.variables[varname] = Variable(self, varname, nc_dtype,
463+
self.variables[varname] = Variable(self, varname, datatype,
464464
dimensions=dimensions, fill_value=fill_value)
465465
return self.variables[varname]
466466

467-
def createVariable(self, varname, nc_dtype, dimensions=(), fill_value=None):
467+
def createVariable(self, varname, datatype, dimensions=(), fill_value=None):
468468
"""
469-
createVariable(self, varname, nc_dtype, dimensions=(), fill_value=None)
469+
createVariable(self, varname, datatype, dimensions=(), fill_value=None)
470470
471471
Same as ``pnetcdf.File.def_var``
472472
"""
473-
return self.def_var(varname, nc_dtype, dimensions, fill_value)
473+
return self.def_var(varname, datatype, dimensions, fill_value)
474474

475475

476476
def ncattrs(self):

src/pnetcdf/_Variable.pyx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ cdef class Variable:
4444
4545
"""
4646

47-
def __init__(self, file, name, nc_dtype, dimensions=(), **kwargs):
47+
def __init__(self, file, name, datatype, dimensions=(), **kwargs):
4848
"""
49-
__init__(self, file, name, nc_dtype, dimensions=(), **kwargs)
49+
__init__(self, file, name, datatype, dimensions=(), **kwargs)
5050
5151
The constructor for :class:`pnetcdf.Variable`.
5252
5353
:param varname: Name of the new variable.
5454
:type varname: str
5555
56-
:param nc_dtype: The datatype of the new variable. Can be specified by providing a NC module constant,
56+
:param datatype: The datatype of the new variable. Can be specified by providing a NC module constant,
5757
or numpy dtype object, or a string that describes a numpy dtype object. Supported specifiers are:
5858
5959
- ``pnetcdf.NC_CHAR`` or ``S1`` for 1-character string
@@ -71,7 +71,7 @@ cdef class Variable:
7171
- ``pnetcdf.NC_INT64`` or ``i8`` for signed 8-byte integer
7272
- ``pnetcdf.NC_UINT64`` or ``u8`` for unsigned 8-byte integer
7373
74-
:type nc_dtype: int
74+
:type datatype: int
7575
:param dimensions: [Optional] The dimensions of the new variable. Can be either dimension names
7676
or dimension class instances. Default is an empty tuple which means the variable is
7777
a scalar (and therefore has no dimensions).
@@ -104,17 +104,17 @@ cdef class Variable:
104104
self._file = file
105105
_file_id = self._file_id
106106
#TODO: decide whether we need to check xtype at python-level
107-
if isinstance(nc_dtype, str): # conver to numpy datatype object
108-
nc_dtype = np.dtype(nc_dtype)
109-
if isinstance(nc_dtype, np.dtype):
110-
if nc_dtype.str[1:] in _supportedtypes:
111-
xtype = _nptonctype[nc_dtype.str[1:]]
107+
if isinstance(datatype, str): # conver to numpy datatype object
108+
datatype = np.dtype(datatype)
109+
if isinstance(datatype, np.dtype):
110+
if datatype.str[1:] in _supportedtypes:
111+
xtype = _nptonctype[datatype.str[1:]]
112112
else:
113-
raise TypeError('illegal data type, must be one of %s, got %s' % (_supportedtypes, nc_dtype.str[1:]))
114-
elif isinstance(nc_dtype, int):
115-
xtype = nc_dtype
113+
raise TypeError('illegal data type, must be one of %s, got %s' % (_supportedtypes, datatype.str[1:]))
114+
elif isinstance(datatype, int):
115+
xtype = datatype
116116
else:
117-
raise TypeError('illegal data type, must be an int, got %s' % (nc_dtype.str[1:]))
117+
raise TypeError('illegal data type, must be an int, got %s' % (datatype.str[1:]))
118118
self.xtype = xtype
119119
self.dtype = np.dtype(_nctonptype[xtype])
120120

0 commit comments

Comments
 (0)