Add slicing support for ellipsis and None #37
Conversation
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 |
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 ('...')") |
hameerabbasi
Dec 24, 2017
Collaborator
There is a spelling error here. sllipsis
should be Ellipsis
.
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>
.
|
@@ -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") |
hameerabbasi
Dec 24, 2017
Collaborator
This will fail on things like a[1, ...]
where a
is (n,)
-shaped. There should be an additional factor of - index.count(Ellipsis)
here.
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. |
if coords: | ||
coords = np.stack(coords, axis=0) | ||
else: | ||
coords = np.array(coords) |
hameerabbasi
Dec 24, 2017
•
Collaborator
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)
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)
hameerabbasi
Dec 24, 2017
•
Collaborator
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.
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