Skip to content

Commit

Permalink
Merge pull request #665 from Unidata/encoding
Browse files Browse the repository at this point in the history
recognize _Encoding attribute for char and string arrays
  • Loading branch information
jswhit committed May 19, 2017
2 parents d70c01c + 6d50a22 commit f8e55d8
Show file tree
Hide file tree
Showing 11 changed files with 14,865 additions and 13,992 deletions.
14 changes: 14 additions & 0 deletions Changelog
Expand Up @@ -6,6 +6,20 @@
(pull request #652, issues #406 and #295).
* fix for negative times in num2date (issue #659).
* fix for failing tests in numpy 1.13 due to changes in numpy.ma (issue #662).
* Checking for _Encoding attribute for NC_STRING variables, otherwise use
'utf-8'. 'utf-8' is used everywhere else, 'default_encoding' global module
variable is no longer used. getncattr method now takes optional kwarg
'encoding' (default 'utf-8') so encoding of attributes can be specified
if desired. If _Encoding is specified for an NC_CHAR ('S1') variable,
the chartostring utility function is used to convert the array of
characters to an array of strings with one less dimension (the last
dimension is interpreted as the length of each string) when reading the
data. When writing the data, stringtochar is used to convert a numpy
array of fixed length strings to an array of characters with one more
dimension. chartostring and stringtochar now also have an 'encoding' kwarg.
Automatic conversion to/from character to string arrays can be turned off
via a new set_auto_chartostring Dataset and Variable method (default
is True).

version 1.2.7 (tag v1.2.7rel)
==============================
Expand Down
10 changes: 2 additions & 8 deletions conda.recipe/run_test.py
@@ -1,14 +1,8 @@
import os
import netCDF4

# Check OPeNDAP functionality.
url = 'http://geoport-dev.whoi.edu/thredds/dodsC/estofs/atlantic'
nc = netCDF4.Dataset(url)

# Check if it was compiled with cython.
assert nc.filepath() == url

# Run the unittests.
# Run the unittests, skipping the opendap test.
test_dir = os.path.join('test')
os.chdir(test_dir)
os.environ['NO_NET']='1'
os.system('python run_all.py')
252 changes: 215 additions & 37 deletions docs/netCDF4/index.html

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion include/netCDF4.pxi
Expand Up @@ -250,7 +250,6 @@ cdef extern from "netcdf.h":
int nc_create(char *path, int cmode, int *ncidp)
int nc__create(char *path, int cmode, size_t initialsz, size_t *chunksizehintp, int *ncidp)
int nc_open(char *path, int mode, int *ncidp)
int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp)
int nc__open(char *path, int mode, size_t *chunksizehintp, int *ncidp)
int nc_inq_path(int ncid, size_t *pathlen, char *path) nogil
int nc_inq_format_extended(int ncid, int *formatp, int* modep) nogil
Expand Down Expand Up @@ -718,6 +717,11 @@ cdef extern from "netcdf.h":

int nc_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier) nogil


IF HAS_NC_OPEN_MEM:
cdef extern from "netcdf_mem.h":
int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp)

# taken from numpy.pxi in numpy 1.0rc2.
cdef extern from "numpy/arrayobject.h":
ctypedef int npy_intp
Expand Down
28,197 changes: 14,329 additions & 13,868 deletions netCDF4/_netCDF4.c

Large diffs are not rendered by default.

0 comments on commit f8e55d8

Please sign in to comment.