Discussion:
pytables create_carray with scalar error?
(too old to reply)
Christopher O'Grady
2016-09-15 00:05:18 UTC
Permalink
Hi,

I'm a bit new to pytables, but reading the documentation and running with
version 3.2.0 we think the 3 line create_carray code below should work, but
it crashes. Would you have any advice? If I change the "obj=3" to a list
of python scalars then it works. Apologies if I've made an error, and
thanks...

chris

psanaphi103:src$ python
Python 2.7.10 (default, May 27 2015, 10:33:01)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import tables
f = tables.File('my.h5', 'w')
f.create_carray(where='/', name='testname', obj=3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/reg/g/psdm/sw/releases/ana-0.19.11/arch/x86_64-rhel7-gcc48-opt/python/tables/file.py",
line 1248, in create_carray
chunkshape=chunkshape, byteorder=byteorder)
File
"/reg/g/psdm/sw/releases/ana-0.19.11/arch/x86_64-rhel7-gcc48-opt/python/tables/carray.py",
line 212, in __init__
byteorder, _log)
File
"/reg/g/psdm/sw/releases/ana-0.19.11/arch/x86_64-rhel7-gcc48-opt/python/tables/leaf.py",
line 262, in __init__
super(Leaf, self).__init__(parentnode, name, _log)
File
"/reg/g/psdm/sw/releases/ana-0.19.11/arch/x86_64-rhel7-gcc48-opt/python/tables/node.py",
line 270, in __init__
self._v_objectid = self._g_create()
File
"/reg/g/psdm/sw/releases/ana-0.19.11/arch/x86_64-rhel7-gcc48-opt/python/tables/carray.py",
line 217, in _g_create
if min(self.shape) < 1:
ValueError: min() arg is an empty sequence
print tables.__version__
3.2.0
--
You received this message because you are subscribed to the Google Groups "pytables-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pytables-users+***@googlegroups.com.
To post to this group, send an email to pytables-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrea Bedini
2016-09-15 06:17:21 UTC
Permalink
Thanks for educating me Chris! :)

I checked and noticed that it works with create_array but not with create_carray.

Andrea
Hi Andrea,
http://www.pytables.org/usersguide/libref/file_class.html <http://www.pytables.org/usersguide/libref/file_class.html>
obj : python object
The array or scalar to be saved. Accepted types are NumPy arrays and scalars, as well as native Python sequences and scalars, provided that values are regular (i.e. they are not like [[1,2],2]) and homogeneous (i.e. all the elements are of the same type).
Such behavior would make our code cleaner, since we could use one call to handle multiple types of data.
Thanks for the thoughts 
 appreciated 

chris
Hi Chris,
I'm a bit new to pytables, but reading the documentation and running with version 3.2.0 we think the 3 line create_carray code below should work, but it crashes. Would you have any advice? If I change the "obj=3" to a list of python scalars then it works. Apologies if I've made an error, and thanks...
Passing `f.create_carray` a single scalar sounds counter-intuitive to me. It naturally expects an array or a list. Where did you get the idea it should make sense?
Andrea
--
Andrea Bedini
@andreabedini, http://www.andreabedini.com <http://www.andreabedini.com/>
See the impact of my research at https://impactstory.org/AndreaBedini <https://impactstory.org/AndreaBedini>
use https://keybase.io/andreabedini <https://keybase.io/andreabedini> to send me encrypted messages
Key fingerprint = 17D5 FB49 FA18 A068 CF53 C5C2 9503 64C1 B2D5 9591
--
Andrea Bedini
@andreabedini, http://www.andreabedini.com

See the impact of my research at https://impactstory.org/AndreaBedini
use https://keybase.io/andreabedini to send me encrypted messages
Key fingerprint = 17D5 FB49 FA18 A068 CF53 C5C2 9503 64C1 B2D5 9591
--
You received this message because you are subscribed to the Google Groups "pytables-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pytables-users+***@googlegroups.com.
To post to this group, send an email to pytables-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Francesc Alted
2016-09-15 09:09:49 UTC
Permalink
Good point, although using a chunked container (CArray) for just an scalar
is just wasting a lot of resources, and this should raise a
`PerformanceWarning` at very least. For storing a scalar an Array object,
or better yet, an HDF5 attribute, would be the right thing to do.

Francesc
Post by Andrea Bedini
Thanks for educating me Chris! :)
I checked and noticed that it works with create_array but not with create_carray.
Andrea
Hi Andrea,
The documentation for create_carray on this page suggests that it should
http://www.pytables.org/usersguide/libref/file_class.html
*obj* : python object
The array or scalar to be saved. Accepted types are NumPy arrays and
scalars, as well as native Python sequences and scalars, provided that
values are regular (i.e. they are not like [[1,2],2]) and homogeneous
(i.e. all the elements are of the same type).
Such behavior would make our code cleaner, since we could use one call to
handle multiple types of data.
Thanks for the thoughts 
 appreciated 

chris
Hi Chris,
I'm a bit new to pytables, but reading the documentation and running with
version 3.2.0 we think the 3 line create_carray code below should work, but
it crashes. Would you have any advice? If I change the "obj=3" to a list
of python scalars then it works. Apologies if I've made an error, and
thanks...
Passing `f.create_carray` a single scalar sounds counter-intuitive to me.
It naturally expects an array or a list. Where did you get the idea
it should make sense?
Andrea
--
Andrea Bedini
@andreabedini, http://www.andreabedini.com
See the impact of my research at https://impactstory.org/AndreaBedini
use https://keybase.io/andreabedini to send me encrypted messages
Key fingerprint = 17D5 FB49 FA18 A068 CF53 C5C2 9503 64C1 B2D5 9591
--
Andrea Bedini
@andreabedini, http://www.andreabedini.com
See the impact of my research at https://impactstory.org/AndreaBedini
use https://keybase.io/andreabedini to send me encrypted messages
Key fingerprint = 17D5 FB49 FA18 A068 CF53 C5C2 9503 64C1 B2D5 9591
--
You received this message because you are subscribed to the Google Groups
"pytables-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Francesc Alted
--
You received this message because you are subscribed to the Google Groups "pytables-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pytables-users+***@googlegroups.com.
To post to this group, send an email to pytables-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...