Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

MAINT: an easier way to make ranges from slices #3123

Merged
merged 1 commit into from

3 participants

CJ Carey Coveralls Pauli Virtanen
CJ Carey

No description provided.

Coveralls

Coverage Status

Coverage remained the same when pulling 799511e on perimosocordiae:patch-2 into 5739a8b on scipy:master.

Pauli Virtanen pv merged commit b2f7f87 into from
Pauli Virtanen
Owner
pv commented

Thanks, merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 7 deletions.
  1. +4 −7 scipy/sparse/dok.py
11 scipy/sparse/dok.py
View
@@ -160,8 +160,7 @@ def __getitem__(self, key):
# or sequence, unfold it first and call __getitem__ recursively.
if isinstance(i, slice):
- # Is there an easier way to do this?
- seq = xrange(i.start or 0, i.stop or self.shape[0], i.step or 1)
+ seq = xrange(*i.indices(self.shape[0]))
elif _is_sequence(i):
seq = i
else:
@@ -199,8 +198,7 @@ def __getitem__(self, key):
# Below here, j is a sequence, but i is an integer
if isinstance(j, slice):
- # Is there an easier way to do this?
- seq = xrange(j.start or 0, j.stop or self.shape[1], j.step or 1)
+ seq = xrange(*j.indices(self.shape[1]))
elif _is_sequence(j):
seq = j
else:
@@ -255,8 +253,7 @@ def __setitem__(self, key, value):
# Either i or j is a slice, sequence, or invalid. If i is a slice
# or sequence, unfold it first and call __setitem__ recursively.
if isinstance(i, slice):
- # Is there an easier way to do this?
- seq = xrange(i.start or 0, i.stop or self.shape[0], i.step or 1)
+ seq = xrange(*i.indices(self.shape[0]))
elif _is_sequence(i):
seq = i
else:
@@ -297,7 +294,7 @@ def __setitem__(self, key, value):
else:
# Process j
if isinstance(j, slice):
- seq = xrange(j.start or 0, j.stop or self.shape[1], j.step or 1)
+ seq = xrange(*j.indices(self.shape[1]))
elif _is_sequence(j):
seq = j
else:
Something went wrong with that request. Please try again.