Skip to content

Commit 07176bb

Browse files
committed
FIX-#2253: fixed cases where lookup is slice
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
1 parent bde303d commit 07176bb

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

modin/pandas/indexing.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ def is_slice(x):
6060
return isinstance(x, slice)
6161

6262

63+
def compute_sliced_len(slc, sequence_len):
64+
"""
65+
Compute length of sliced object.
66+
67+
Parameters
68+
----------
69+
slc: slice
70+
Slice object
71+
sequence_len: int
72+
Length of sequence, to which slice will be applied
73+
74+
Returns
75+
-------
76+
int
77+
Length of object after applying slice object on it.
78+
"""
79+
# This will translate slice to a range, from which we can retrieve length
80+
return len(range(*slc.indices(sequence_len)))
81+
82+
6383
def is_2d(x):
6484
"""
6585
Implement [METHOD_NAME].
@@ -441,13 +461,23 @@ def _determine_setitem_axis(self, row_lookup, col_lookup, row_scaler, col_scaler
441461
if self.df.shape == (1, 1):
442462
return None if not (row_scaler ^ col_scaler) else 1 if row_scaler else 0
443463

464+
def get_axis(axis):
465+
return self.qc.index if axis == 0 else self.qc.columns
466+
467+
row_look_len, col_look_len = [
468+
len(lookup)
469+
if not isinstance(lookup, slice)
470+
else compute_sliced_len(lookup, len(get_axis(i)))
471+
for i, lookup in enumerate([row_lookup, col_lookup])
472+
]
473+
444474
if (
445-
len(row_lookup) == len(self.qc.index)
446-
and len(col_lookup) == 1
447-
and hasattr(self.df, "columns")
475+
row_look_len == len(self.qc.index)
476+
and col_look_len == 1
477+
and isinstance(self.df, DataFrame)
448478
):
449479
axis = 0
450-
elif len(col_lookup) == len(self.qc.columns) and len(row_lookup) == 1:
480+
elif col_look_len == len(self.qc.columns) and row_look_len == 1:
451481
axis = 1
452482
else:
453483
axis = None

0 commit comments

Comments
 (0)