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 slicing support for ellipsis and None #37
Conversation
7fe0638
to
b9c2561
Compare
b9c2561
to
df1f468
Compare
Looks great to me. One minor point: A check to see there isn't more than one Edit: Ideally, the exception should be |
Added such a test. It looks like Python handles this check for us. |
Ah, never mind. My test was faulty here |
16ba00c
to
06ef208
Compare
sparse/core.py
Outdated
if len(index) - index.count(None) > self.ndim: | ||
raise IndexError("too many indices for array") | ||
if index.count(Ellipsis) > 1: | ||
raise IndexError("an index can only have a single sllipsis ('...')") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a spelling error here. sllipsis
should be Ellipsis
.
Thanks. Fixed
…On Sun, Dec 24, 2017 at 8:42 AM, Hameer Abbasi ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In sparse/core.py
<https://github.com/mrocklin/sparse/pull/37#discussion_r158605898>:
> @@ -233,10 +233,19 @@ def __sizeof__(self):
def __getitem__(self, index):
if not isinstance(index, tuple):
index = (index,)
- index = tuple(ind + self.shape[i] if isinstance(ind, numbers.Integral) and ind < 0 else ind
+ if len(index) - index.count(None) > self.ndim:
+ raise IndexError("too many indices for array")
+ if index.count(Ellipsis) > 1:
+ raise IndexError("an index can only have a single sllipsis ('...')")
There is a spelling error here. sllipsis should be Ellipsis.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://github.com/mrocklin/sparse/pull/37#pullrequestreview-85445245>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASszMWNg0ryroKdK3h2tKt7HzJT9hiKks5tDn7agaJpZM4RLtHw>
.
|
06ef208
to
852ecdb
Compare
sparse/core.py
Outdated
@@ -233,10 +233,19 @@ def __sizeof__(self): | |||
def __getitem__(self, index): | |||
if not isinstance(index, tuple): | |||
index = (index,) | |||
index = tuple(ind + self.shape[i] if isinstance(ind, numbers.Integral) and ind < 0 else ind | |||
if len(index) - index.count(None) > self.ndim: | |||
raise IndexError("too many indices for array") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail on things like a[1, ...]
where a
is (n,)
-shaped. There should be an additional factor of - index.count(Ellipsis)
here.
Sorry for requesting so much changes. Here's the last one. It's nitpicky, sure, but I want to make sure all our bases are covered. |
No, this is great. Thank you for all of your work reviewing here. |
sparse/core.py
Outdated
if coords: | ||
coords = np.stack(coords, axis=0) | ||
else: | ||
coords = np.array(coords) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be missing something here, but won't np.array([])
create an array with a dtype
of float64
and a shape of (0,)
? It would be much nicer to do this: coords = np.empty((len(shape), 0), dtype=np.uint8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also to specify a dtype
even in the first case, as for empty arrays it might also be float64
. np.result_type
and np.min_scalar_type
should be useful here.
Some minor comments that will hopefully address the CI failures. |
I ran into this while testing https://github.com/mrocklin/sparse/pull/35 .
@hameerabbasi if you have a moment to look this over I would welcome your review