Repository: modin-project/modin

Issue:
New API: `take` for Series and DataFrame

### Describe the problem
<!-- Describe the problem clearly here. -->
`take` is very similar to `iloc` and should be fairly straightforward to implement. `Series` and `DataFrame` can share the same implementation.




Discussion:

Resolving patch:
diff --git a/modin/pandas/base.py b/modin/pandas/base.py
--- a/modin/pandas/base.py
+++ b/modin/pandas/base.py
@@ -2812,9 +2812,10 @@ def swaplevel(self, i=-2, j=-1, axis=0):
         return self._default_to_pandas("swaplevel", i=i, j=j, axis=axis)
 
     def take(self, indices, axis=0, is_copy=True, **kwargs):
-        return self._default_to_pandas(
-            "take", indices, axis=axis, is_copy=is_copy, **kwargs
-        )
+        axis = self._get_axis_number(axis)
+        slice_obj = indices if axis == 0 else (slice(None), indices)
+        result = self.iloc[slice_obj]
+        return result if not is_copy else result.copy()
 
     def tail(self, n=5):
         """Get the last n rows of the DataFrame.
diff --git a/modin/pandas/series.py b/modin/pandas/series.py
--- a/modin/pandas/series.py
+++ b/modin/pandas/series.py
@@ -1015,9 +1015,7 @@ def tail(self, n=5):
         return super(Series, self).tail(n)
 
     def take(self, indices, axis=0, is_copy=False, **kwargs):
-        self._default_to_pandas(
-            pandas.Series.take, indices, axis=axis, is_copy=is_copy, **kwargs
-        )
+        return super(Series, self).take(indices, axis=axis, is_copy=is_copy, **kwargs)
 
     def to_frame(self, name=None):
         from .dataframe import DataFrame


Test patch:
diff --git a/modin/pandas/test/test_dataframe.py b/modin/pandas/test/test_dataframe.py
--- a/modin/pandas/test/test_dataframe.py
+++ b/modin/pandas/test/test_dataframe.py
@@ -2564,7 +2564,7 @@ def test_swaplevel(self):
             df.swaplevel("Number", "Color")
 
     def test_take(self):
-        df = pd.DataFrame(
+        modin_df = pd.DataFrame(
             [
                 ("falcon", "bird", 389.0),
                 ("parrot", "bird", 24.0),
@@ -2574,8 +2574,18 @@ def test_take(self):
             columns=["name", "class", "max_speed"],
             index=[0, 2, 3, 1],
         )
-        with pytest.warns(UserWarning):
-            df.take([0, 3])
+        pandas_df = pandas.DataFrame(
+            [
+                ("falcon", "bird", 389.0),
+                ("parrot", "bird", 24.0),
+                ("lion", "mammal", 80.5),
+                ("monkey", "mammal", np.nan),
+            ],
+            columns=["name", "class", "max_speed"],
+            index=[0, 2, 3, 1],
+        )
+        df_equals(modin_df.take([0, 3]), pandas_df.take([0, 3]))
+        df_equals(modin_df.take([2], axis=1), pandas_df.take([2], axis=1))
 
     @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
     def test_to_records(self, request, data):
diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py
--- a/modin/pandas/test/test_series.py
+++ b/modin/pandas/test/test_series.py
@@ -2501,9 +2501,15 @@ def test_tail(data, n):
 
 
 def test_take():
-    series = pd.Series([1, 2, 3, 4], index=[0, 2, 3, 1])
-    with pytest.warns(UserWarning):
-        series.take([0, 3])
+    modin_s = pd.Series(["falcon", "parrot", "lion", "cat"], index=[0, 2, 3, 1])
+    pandas_s = pandas.Series(["falcon", "parrot", "lion", "cat"], index=[0, 2, 3, 1])
+    a = modin_s.take([0, 3])
+    df_equals(a, pandas_s.take([0, 3]))
+    try:
+        pandas_s.take([2], axis=1)
+    except Exception as e:
+        with pytest.raises(type(e)):
+            modin_s.take([2], axis=1)
 
 
 @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)