Skip to content

add iteration for lgdo collections#231

Draft
ggmarshall wants to merge 2 commits into
mainfrom
iterator
Draft

add iteration for lgdo collections#231
ggmarshall wants to merge 2 commits into
mainfrom
iterator

Conversation

@ggmarshall

@ggmarshall ggmarshall commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Maybe a better way to do this consistently over our types but here is a quick iterator for Table.

@ggmarshall ggmarshall marked this pull request as ready for review June 1, 2026 22:01
Copilot AI review requested due to automatic review settings June 1, 2026 22:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an iter_chunks method to Table that yields consecutive row-range views of the table, plus tests covering even/uneven divisions, slice equivalence, memory sharing, and invalid input.

Changes:

  • New Table.iter_chunks(chunk_size) generator that validates chunk_size > 0 and yields self[start:start+chunk_size] for each window.
  • Imports Iterator from collections.abc.
  • Adds test_iter_chunks covering happy paths, edge cases, and invalid arguments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/lgdo/types/table.py Adds iter_chunks method and Iterator import
tests/types/test_table.py Adds tests for the new chunked iteration API

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.09%. Comparing base (e8acb78) to head (de4bfc5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #231      +/-   ##
==========================================
+ Coverage   86.04%   86.09%   +0.04%     
==========================================
  Files          21       21              
  Lines        1806     1812       +6     
==========================================
+ Hits         1554     1560       +6     
  Misses        252      252              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ggmarshall ggmarshall marked this pull request as draft June 1, 2026 22:05
@ggmarshall ggmarshall requested a review from Copilot June 1, 2026 22:17
@ggmarshall ggmarshall marked this pull request as ready for review June 1, 2026 22:17
@ggmarshall ggmarshall changed the title add table iteration add iteration for lgdo collections Jun 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/lgdo/types/lgdo.py Outdated
@ggmarshall

ggmarshall commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Array returns a numpy array not an lgdo, do we want to change this?

Here's the breakdown by type:


Array / ArrayOfEqualSizedArrays / subclasses — yes, trivially. self.nda[key] is already a numpy view. The only thing missing is wrapping it back into the LGDO type:


# current
def __getitem__(self, key):
    return self.nda[key]          # numpy view, wrong type

# zero-copy fix
def __getitem__(self, key):
    return type(self)(nda=self.nda[key], ...)   # LGDO, still a view

@gipert

gipert commented Jun 2, 2026

Copy link
Copy Markdown
Member

I think we should always return an LGDO

@gipert gipert requested a review from iguinn June 2, 2026 09:31
@iguinn

iguinn commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Yeah agreed. I was reluctant to change this due to fear of breaking things, but I think that's how it should be. If you want a numpy array you call nda or view_as("np")

@ggmarshall ggmarshall marked this pull request as draft June 5, 2026 21:36
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.

4 participants