Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: indexing length 1 table with bool array #2

Open
BastiaanBergman opened this issue Dec 20, 2018 · 2 comments
Open

bug: indexing length 1 table with bool array #2

BastiaanBergman opened this issue Dec 20, 2018 · 2 comments
Labels
enhancement New feature or request

Comments

@BastiaanBergman
Copy link
Owner

When indexing a length 1 table with a bool array, the index is treated a s a single integer number. This is because int(np.array([False])) is treated as 0 and will not raise an error inside the Tabel.getitem method.

Example code:

# Correct output
tbl = Tabel({'a':[1,1.1],'b':[2,2.2]})
tbl[tbl['a']>2, :]
>>>     a   | b
>>>    -----+-----
>>>    0 rows ['<f8', '<f8']

# Incorrect output
tbl = Tabel({'a':[1],'b':[2]})
tbl[tbl['a']>2, :]
>>>    (1, 2)

# Workaround:
tbl = Tabel({'a':[1],'b':[2]})
tbl[tuple(tbl['a']>2), :]
>>>      a   | b
>>>     -----+-----
>>>     0 rows ['<i8', '<i8']

@BastiaanBergman
Copy link
Owner Author

Actually, the workaround is not good. Some numpy versions don't allow bool indexing with tubples.

@BastiaanBergman BastiaanBergman added the enhancement New feature or request label May 20, 2019
@BastiaanBergman
Copy link
Owner Author

To prevent users from doing this we need to implement python type checking with type hints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant