Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

ctable and cols setitem allows you to set value to ANY type with the right __len__ #307

Closed
suntzu86 opened this issue Jun 15, 2016 · 0 comments

Comments

@suntzu86
Copy link

test_ctable = bcolz.ctable(numpy.zeros(2, dtype='f8, i4'))
test_ctable['f0'] = dict(a=1,b='bar')  # ('a',2), ['foo',tuple], etc all work, just has to have len() == 2

dict is missing all kinds of functions that are later expected (like say purge and flush if I delete f0).

This goes through __setitem__ for ctable and cols. The former passes straight to the latter b/c I'm setting an existing name. The latter setitem only checks len:
https://github.com/Blosc/bcolz/blob/master/bcolz/ctable.py#L86

Context:
I ran across this while trying to see if there's a way to do += on bcolz objects. In particular:

test_ctable = bcolz.ctable(numpy.zeros(2, dtype='f8, i4'))
test_ctable['f0'] += 1.0  # fails, no += operator
test_ctable['f0'] += numpy.ones(2)  # success! b/c numpy's ladd and radd are both type-promoting and setitem accepts anything w/length 2
type(test_ctable)  # numpy.ndarray
test_ctable['f0'] += 1  # success! b/c it's a numpy array now
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant