Repository: modin-project/modin (python)

Issue:
`Series.cumsum` failed with the following error: `ValueError: assignment destination is read-only`
Modin: b8323b5f46e25d257c08f55745c018197f7530f5
```python
import modin.pandas as pd
pd.Series([1, 2, 3], dtype="Int64").cumsum()  # <- ValueError: assignment destination is read-only
```

Pull request description:
FIX-#6771: avoid `ValueError: assignment destination is read-only` for `cumsum`
<!--
Thank you for your contribution!
Please review the contributing docs: https://modin.readthedocs.io/en/latest/development/contributing.html
if you have questions about contributing.
-->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

- [x] first commit message and PR title follow format outlined [here](https://modin.readthedocs.io/en/latest/development/contributing.html#commit-message-formatting)
  > **_NOTE:_**  If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.
- [x] passes `flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py`
- [x] passes `black --check modin/ asv_bench/benchmarks scripts/doc_checker.py`
- [x] signed commit with `git commit -s` <!-- you can amend your commit with a signature via `git commit -amend -s` -->
- [x] Resolves #6771 <!-- issue must be created for each patch -->
- [x] tests added and passing
- [x] module layout described at `docs/development/architecture.rst` is up-to-date <!-- if you have added, renamed or removed files or directories please update the documentation accordingly -->


Patch:
diff --git a/modin/core/dataframe/pandas/partitioning/axis_partition.py b/modin/core/dataframe/pandas/partitioning/axis_partition.py
index 30ed90c4..bfc94605 100644
--- a/modin/core/dataframe/pandas/partitioning/axis_partition.py
+++ b/modin/core/dataframe/pandas/partitioning/axis_partition.py
@@ -422,7 +422,13 @@ class PandasDataframeAxisPartition(BaseDataframeAxisPartition):
         dataframe = pandas.concat(list(partitions), axis=axis, copy=False)
         with warnings.catch_warnings():
             warnings.filterwarnings("ignore", category=FutureWarning)
-            result = func(dataframe, *f_args, **f_kwargs)
+            try:
+                result = func(dataframe, *f_args, **f_kwargs)
+            except ValueError as err:
+                if "assignment destination is read-only" in str(err):
+                    result = func(dataframe.copy(), *f_args, **f_kwargs)
+                else:
+                    raise err
 
         if num_splits == 1:
             # If we're not going to split the result, we don't need to specify
diff --git a/modin/core/dataframe/pandas/partitioning/partition.py b/modin/core/dataframe/pandas/partitioning/partition.py
index 38cc41ca..224c40a1 100644
--- a/modin/core/dataframe/pandas/partitioning/partition.py
+++ b/modin/core/dataframe/pandas/partitioning/partition.py
@@ -209,7 +209,7 @@ class PandasDataframePartition(ABC):  # pragma: no cover
         If the underlying object is a pandas DataFrame, this will return
         a 2D NumPy array.
         """
-        return self.apply(lambda df, **kwargs: df.to_numpy(**kwargs)).get()
+        return self.apply(lambda df: df.to_numpy(**kwargs)).get()
 
     @staticmethod
     def _iloc(df, row_labels, col_labels):  # noqa: RT01, PR01
diff --git a/modin/core/execution/ray/generic/partitioning/partition_manager.py b/modin/core/execution/ray/generic/partitioning/partition_manager.py
index f5795d07..d4b61b25 100644
--- a/modin/core/execution/ray/generic/partitioning/partition_manager.py
+++ b/modin/core/execution/ray/generic/partitioning/partition_manager.py
@@ -42,7 +42,7 @@ class GenericRayDataframePartitionManager(PandasDataframePartitionManager):
         """
         if partitions.shape[1] == 1:
             parts = cls.get_objects_from_partitions(partitions.flatten())
-            parts = [part.to_numpy() for part in parts]
+            parts = [part.to_numpy(**kwargs) for part in parts]
         else:
             parts = RayWrapper.materialize(
                 [
diff --git a/modin/core/execution/unidist/generic/partitioning/partition_manager.py b/modin/core/execution/unidist/generic/partitioning/partition_manager.py
index 666152a0..8052c5cc 100644
--- a/modin/core/execution/unidist/generic/partitioning/partition_manager.py
+++ b/modin/core/execution/unidist/generic/partitioning/partition_manager.py
@@ -42,7 +42,7 @@ class GenericUnidistDataframePartitionManager(PandasDataframePartitionManager):
         """
         if partitions.shape[1] == 1:
             parts = cls.get_objects_from_partitions(partitions.flatten())
-            parts = [part.to_numpy() for part in parts]
+            parts = [part.to_numpy(**kwargs) for part in parts]
         else:
             parts = UnidistWrapper.materialize(
                 [


Test patch:
diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py
index 1b2c5eb0..e64e1371 100644
--- a/modin/pandas/test/test_series.py
+++ b/modin/pandas/test/test_series.py
@@ -1474,6 +1474,10 @@ def test_cumsum(data, skipna):
         df_equals(modin_series.cumsum(skipna=skipna), pandas_result)
 
 
+def test_cumsum_6771():
+    _ = to_pandas(pd.Series([1, 2, 3], dtype="Int64").cumsum())
+
+
 @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
 def test_describe(data):
     modin_series, pandas_series = create_test_series(data)
@@ -3475,6 +3479,15 @@ def test_to_numpy(data):
     assert_array_equal(modin_series.to_numpy(), pandas_series.to_numpy())
 
 
+def test_to_numpy_dtype():
+    modin_series, pandas_series = create_test_series(test_data["float_nan_data"])
+    assert_array_equal(
+        modin_series.to_numpy(dtype="int64"),
+        pandas_series.to_numpy(dtype="int64"),
+        strict=True,
+    )
+
+
 @pytest.mark.parametrize(
     "data",
     test_data_values + test_data_large_categorical_series_values,