You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/15 23:22:11 UTC
[GitHub] [arrow] bmschmidt opened a new issue, #14988: Raise IndexError when pa.Schema.get_field_index fails
bmschmidt opened a new issue, #14988:
URL: https://github.com/apache/arrow/issues/14988
### Describe the enhancement requested
Thanks to everyone who works on this project.
I want to report what seems to me a less-than-ideal behavior in the python API. `Schema.get_field_index()` returns -1 to indicate that a given column is not in the list (C-style), but `Schema.get_field(-1)` returns the last element in the list (python-style). In concert these can raise opaque bugs that are a little hard to track down.
Example:
```python
schema = pa.schema([
pa.field('n_legs', pa.int64()),
pa.field('animals', pa.string()),
])
# Returns -1 to indicate that the column doesn't exist
nonexistent_field = schema.get_field_index("n_eyes")
# Happily consumes -1 to return the field for 'animals.'
schema.field(nonexistent_field)
```
I would expect a python library would raise a `ValueError` when you request the index for a key that doesn't exist. That's my proposal here, I guess. (That is, schema.get_field_index should behave the same as python's native `List.index()` method.); I'm also not convinced that negative-style indexing on schema.field is very desirable, but that's probably it's the sort of feature that can't be removed. Failing either of these, it might be worth putting a note in the docs that `Schema.field` and `Schema.get_field_index` don't play as well together as one might expect.
### Component(s)
Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Raise IndexError when pa.Schema.get_field_index fails [arrow]
Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic commented on issue #14988:
URL: https://github.com/apache/arrow/issues/14988#issuecomment-3921584184
This issue has been marked as stale because it has had no activity in the past 2 years. Please remove the stale label or comment below, or this issue will be closed in 14 days.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Raise IndexError when pa.Schema.get_field_index fails [arrow]
Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic closed issue #14988: [Python] Raise IndexError when pa.Schema.get_field_index fails
URL: https://github.com/apache/arrow/issues/14988
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org