Repository: modin-project/modin

Issue:
Modin resample error
hi ,
i used resample method with ray modin and ı got error that was TypeError: ‘Resampler’ object is not subscriptable .  My code works with pandas .
my code is :
team_md.resample(‘3T’)[[‘Value’]].mean()
how can i solve this ?

thanks ! 

Murat KOÇ
Machine Learning Engineer



Discussion:
Hi, @kocmurat93!
Thank you for the report. Looks like `Resampler` object hasn't `__getitem__` method, that's reason of your issue. This is bug and we will fix that.
hi @prutskov ,

We would like to help you to fix the bug in order to speed up the process . Our team can fix this bug.


@kocmurat93 it would be great! Before creating of corresponded PR, please, note about our [contributing guidelines](https://modin.readthedocs.io/en/latest/contributing.html).
@prutskov Hi! What's the current status of the issue? I may try to fix the bug if it's not that complex.
@dikuchan Please feel free to make the change, it is fairly straightforward. 

@prutskov Are you able to assist here as well?
@devin-petersohn Yes, sure, I'll help.
@dikuchan If you have any questions feel free to ask! Note about our [contributing guidelines](https://modin.readthedocs.io/en/latest/contributing.html).

Resolving patch:
diff --git a/modin/pandas/base.py b/modin/pandas/base.py
--- a/modin/pandas/base.py
+++ b/modin/pandas/base.py
@@ -3127,6 +3127,42 @@ def __init__(
         ]
         self.__groups = self.__get_groups(*self.resample_args)
 
+    def __getitem__(self, key):
+        """
+        Get ``Resampler`` based on `key` columns of original dataframe.
+
+        Parameters
+        ----------
+        key : str or list
+            String or list of selections.
+
+        Returns
+        -------
+        modin.pandas.BasePandasDataset
+            New ``Resampler`` based on `key` columns subset
+            of the original dataframe.
+        """
+
+        def _get_new_resampler(key):
+            subset = self._dataframe[key]
+            resampler = type(self)(subset, *self.resample_args)
+            return resampler
+
+        from .series import Series
+
+        if isinstance(
+            key, (list, tuple, Series, pandas.Series, pandas.Index, np.ndarray)
+        ):
+            if len(self._dataframe.columns.intersection(key)) != len(key):
+                missed_keys = list(set(key).difference(self._dataframe.columns))
+                raise KeyError(f"Columns not found: {str(sorted(missed_keys))[1:-1]}")
+            return _get_new_resampler(list(key))
+
+        if key not in self._dataframe:
+            raise KeyError(f"Column not found: {key}")
+
+        return _get_new_resampler(key)
+
     def __get_groups(
         self,
         rule,


Test patch:
diff --git a/modin/pandas/test/dataframe/test_default.py b/modin/pandas/test/dataframe/test_default.py
--- a/modin/pandas/test/dataframe/test_default.py
+++ b/modin/pandas/test/dataframe/test_default.py
@@ -762,6 +762,43 @@ def test_resample_specific(rule, closed, label, on, level):
         )
 
 
+@pytest.mark.parametrize(
+    "columns",
+    [
+        "volume",
+        "date",
+        ["volume"],
+        ["price", "date"],
+        ("volume",),
+        pandas.Series(["volume"]),
+        pandas.Index(["volume"]),
+        ["volume", "volume", "volume"],
+        ["volume", "price", "date"],
+    ],
+    ids=[
+        "column",
+        "missed_column",
+        "list",
+        "missed_column",
+        "tuple",
+        "series",
+        "index",
+        "duplicate_column",
+        "missed_columns",
+    ],
+)
+def test_resample_getitem(columns):
+    index = pandas.date_range("1/1/2013", periods=9, freq="T")
+    data = {
+        "price": range(9),
+        "volume": range(10, 19),
+    }
+    eval_general(
+        *create_test_dfs(data, index=index),
+        lambda df: df.resample("3T")[columns].mean(),
+    )
+
+
 @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
 @pytest.mark.parametrize("index", ["default", "ndarray", "has_duplicates"])
 @pytest.mark.parametrize("axis", [0, 1])