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

feat: add slicing to vectors #28

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add slicing to vectors
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Feb 24, 2024
commit a570543e8281188eded07abb62630a05ad7c9a67
5 changes: 5 additions & 0 deletions src/vector/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
self, **{k: v.reshape(*args, order=order) for k, v in dataclass_items(full)}
)

def __getitem__(self, index: Any) -> "Self":
"""Return a new object with the given slice applied."""
full = full_shaped(self) # TODO: detect if need to make a full-shaped copy
return replace(full, **{k: v[index] for k, v in dataclass_items(full)})

Check warning on line 73 in src/vector/_base.py

View check run for this annotation

Codecov / codecov/patch

src/vector/_base.py#L72-L73

Added lines #L72 - L73 were not covered by tests

# ===============================================================
# Collection

Expand Down
Loading