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

Last feature index is inconsistent #1187

Open
mwtoews opened this issue Jan 29, 2023 · 0 comments
Open

Last feature index is inconsistent #1187

mwtoews opened this issue Jan 29, 2023 · 0 comments
Labels
Milestone

Comments

@mwtoews
Copy link
Member

mwtoews commented Jan 29, 2023

This is an issue with drivers like GPKG which have feature indexes that start with 1 (and not 0). For example poly.gpkg with 10 features:

import fiona

ds = fiona.open("poly.gpkg")

assert ds[0] is None
print(ds[1]["id"])   # 1  <- the first
print(ds[10]["id"])  # 10 <- the last
print(ds[-1]["id"])  # 9  <- whoops!

with a -1 getitem index, it is usually expected to get the last item, but instead the second last item is returned.


Some ideas for the next development cycle is to deprecate negative indices for getitem, since they are not always zero-indexed, and introduce something like iloc (or irec?) similar to pandas to always retrieve the zero-indexed records.

@mwtoews mwtoews added the bug label Jan 29, 2023
@mwtoews mwtoews added this to the 2.0 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant