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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to