Unidata/netcdf4-python — pull request #220 by shoyer (2014-03-03 02:06:38+00:00)
Title: __getitem__ for 0d arrays returns 0d arrays (not 1d arrays)

This fix ensures that indexing a 0-dimensional array returns a 0-dimensional
numpy array (consistent with numpy's behavior), not a 1-dimensional array with
one element, which is the current behavior.

I'm sure there is a more elegant solution to this issue, but I think this is
one of the better options short of rewriting the core indexing routines. As an
alternative, I did try removing the hack `if nDims == 0: ...` at the start of
_StartCountStride but that definitely broke things. Presumably that hack is
there for a reason?

Note that to fully match how numpy handles 0-dimensional arrays, we would
actually raise an error when somebody tries to access or set a 0-dimensional
variable with `v[:]`. The right syntax for indexing a 0-dimensional array is
somewhat obscure: `v[()]` (using an empty tuple) or `v[...]`. But I avoided
this option because it would assuredly break some user code.

My fix here will probably break some poorly constructed user code, too, if it
relied on the broken 0-d arrays are always 1-d behavior. The right way to
handle this would have been to use `np.asscalar`. So there may be a case for
saving this until the next major version.