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

Add __len__ method to Index #207

Merged
merged 2 commits into from
Feb 5, 2022
Merged

Conversation

adamjstewart
Copy link
Collaborator

This PR adds a __len__ method to Index, defining the length of an index as the number of entries in that index. This is analogous to the definition of length for Python sets.

This PR also documents and tests the get_size method which provides identical functionality. This method has never been documented before. Should we deprecate or remove it in favor of __len__? It's definitely more Pythonic to rely on these kinds of magic methods instead of get_* and set_* methods.

Closes #194

@hobu

@hobu
Copy link
Member

hobu commented Feb 4, 2022

Should we deprecate or remove it in favor of __len__?

Deprecate is fine. Rtree comes from a time before there were properties in Python 😄, which is why there's get_*-style stuff.

It's definitely more Pythonic

What was Pythonic 15 years ago is not necessarily the same thing as today. Rtree could definitely use a thorough once over in that regard.

@hobu hobu merged commit 6f638cc into Toblerity:master Feb 5, 2022
@hobu hobu added this to the 1.0.0 milestone Feb 5, 2022
@adamjstewart adamjstewart deleted the features/len branch February 5, 2022 17:08
@EwoutH
Copy link
Contributor

EwoutH commented Jul 10, 2024

For some reason this warning is still triggered in rtree's own CI.

=============================== warnings summary ===============================
rtree/index.py::rtree.index.Index.__init__
  /home/runner/work/rtree/rtree/rtree/index.py:284: DeprecationWarning: index.get_size() is deprecated, use len(index) instead
    warnings.warn(

Is this expected? Could it be that a test is out of date?

@adamjstewart
Copy link
Collaborator Author

Fixed by #323

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

Successfully merging this pull request may close these issues.

Easy way to get number of entries in index
3 participants