[NeXus-code-tickets] [NeXusCode] #156: python: support '|S1' for string data
NeXus Data Format Library and Applications
noreply at nexusformat.org
Fri Jan 30 15:50:09 GMT 2009
#156: python: support '|S1' for string data
-----------------------+----------------------------------------------------
Reporter: Cpascual | Owner: Paul Kienzle
Type: defect | Status: new
Priority: minor | Milestone: NeXus 4.2 Release
Component: bindings | Version: 4.2rc2
Resolution: | Keywords: numpy dtype char
-----------------------+----------------------------------------------------
Comment (by Cpascual):
The ability to deal with numpy string arrays as the **input** would be
interesting for two reasons:
1) It makes the API more consistent (one would not need act differently
depending on whether is using 'char' or other types)
2)It paves the path to multidimensional character arrays.
Regarding the **output**: IMHO, the output should be always the same
regardless of the input, and only dependent on the data shape (i.e., on
what is returned by NXgetinfo(). I think that the most consistent option
is to always return a numpy array of strings:
If the data shape is [m], then the output should be a zero-dimensional
numpy array containing a string of length m
If the data shape is [n,m], then the output should be a n-long 1D numpy
array of strings of length m.
If the data shape is [k,n,m] then the output should be a 2D array [with
shape=(k,n)] of strings of length m.
...
As an exception it could be reasonable to implement it in such a way that
data with shape [m] returns a python string instead of a numpy array of
shape=(,). But, IMHO, always returning numpy makes it more self-
consistent. The user can always convert the output (or slices of it) to
strings using the .tostring() method of the numpy arrays.
I am currently working on my own implementation of this. I will post it as
soon as it is ready.
--
Ticket URL: <http://trac.nexusformat.org/code/ticket/156#comment:4>
NeXus Data Format Library and Applications <http://www.nexusformat.org/>
NeXus Data Format Library and Applications
More information about the NeXus-code-tickets
mailing list