Skip to content

Commit

Permalink
FIX-#6541: fix 'ValueError: buffer source array is read-only' for 'il…
Browse files Browse the repository at this point in the history
…oc' (#6538)

Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev authored Sep 8, 2023
1 parent 67c9c2c commit f4abfc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4241,7 +4241,16 @@ def iloc_mut(partition, row_internal_indices, col_internal_indices, item):
Partition data with updated values.
"""
partition = partition.copy()
partition.iloc[row_internal_indices, col_internal_indices] = item
try:
partition.iloc[row_internal_indices, col_internal_indices] = item
except ValueError:
# `copy` is needed to avoid "ValueError: buffer source array is read-only" for `item`
# because the item may be converted to the type that is in the dataframe.
# TODO: in the future we will need to convert to the correct type manually according
# to the following warning. Example: "FutureWarning: Setting an item of incompatible
# dtype is deprecated and will raise in a future error of pandas. Value '[1.38629436]'
# has dtype incompatible with int64, please explicitly cast to a compatible dtype first."
partition.iloc[row_internal_indices, col_internal_indices] = item.copy()
return partition

new_modin_frame = self._modin_frame.apply_select_indices(
Expand Down
2 changes: 1 addition & 1 deletion modin/numpy/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import modin.numpy as np


def assert_scalar_or_array_equal(x1, x2, err_msg=None):
def assert_scalar_or_array_equal(x1, x2, err_msg=""):
"""
Assert whether the result of the numpy and modin computations are the same.
Expand Down

0 comments on commit f4abfc8

Please sign in to comment.