Skip to content

Commit

Permalink
FIX-modin-project#7093: Make sure 'idxmax' and 'idxmin' can work with…
Browse files Browse the repository at this point in the history
… string columns

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed Apr 16, 2024
1 parent 6d64e08 commit 34c5dab
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
4 changes: 0 additions & 4 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,8 +1868,6 @@ def idxmax(self, axis=0, skipna=True, numeric_only=False): # noqa: PR01, RT01,
"""
Return index of first occurrence of maximum over requested axis.
"""
if not all(d != pandas.api.types.pandas_dtype("O") for d in self._get_dtypes()):
raise TypeError("reduce operation 'argmax' not allowed for this dtype")
axis = self._get_axis_number(axis)
return self._reduce_dimension(
self._query_compiler.idxmax(
Expand All @@ -1881,8 +1879,6 @@ def idxmin(self, axis=0, skipna=True, numeric_only=False): # noqa: PR01, RT01,
"""
Return index of first occurrence of minimum over requested axis.
"""
if not all(d != pandas.api.types.pandas_dtype("O") for d in self._get_dtypes()):
raise TypeError("reduce operation 'argmin' not allowed for this dtype")
axis = self._get_axis_number(axis)
return self._reduce_dimension(
self._query_compiler.idxmin(
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def transpose(self, copy=False, *args) -> DataFrame: # noqa: PR01, RT01, D200
query_compiler=self._query_compiler.transpose(*args)
)

T = property(transpose)
T: DataFrame = property(transpose)

def add(
self, other, axis="columns", level=None, fill_value=None
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ def transpose(self, *args, **kwargs) -> Series: # noqa: PR01, RT01, D200
"""
return self

T = property(transpose)
T: Series = property(transpose)

def truediv(
self, other, level=None, fill_value=None, axis=0
Expand Down
7 changes: 7 additions & 0 deletions modin/tests/pandas/dataframe/test_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ def test_idxmin_idxmax(data, axis, skipna, is_transposed, method):
),
)

@pytest.mark.parametrize("axis", [0, 1])
def test_idxmin_idxmax_string_columns(axis):
# https://github.com/modin-project/modin/issues/7093
modin_df, pandas_df = create_test_dfs([['a', 'b']])
eval_general(modin_df, pandas_df, lambda df: df.idxmax(axis=axis))
eval_general(modin_df, pandas_df, lambda df: df.idxmin(axis=axis))


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_last_valid_index(data):
Expand Down
10 changes: 6 additions & 4 deletions modin/tests/pandas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

from __future__ import annotations

import csv
import functools
import itertools
Expand Down Expand Up @@ -1084,14 +1086,14 @@ def eval_io_from_str(csv_str: str, unique_filename: str, **kwargs):
)


def create_test_dfs(*args, **kwargs):
def create_test_dfs(*args, **kwargs) -> tuple[pd.DataFrame, pandas.DataFrame]:
post_fn = kwargs.pop("post_fn", lambda df: df)
return map(
post_fn, [pd.DataFrame(*args, **kwargs), pandas.DataFrame(*args, **kwargs)]
return tuple(
map(post_fn, [pd.DataFrame(*args, **kwargs), pandas.DataFrame(*args, **kwargs)])
)


def create_test_series(vals, sort=False, **kwargs):
def create_test_series(vals, sort=False, **kwargs) -> tuple[pd.Series, pandas.Series]:
if isinstance(vals, dict):
modin_series = pd.Series(vals[next(iter(vals.keys()))], **kwargs)
pandas_series = pandas.Series(vals[next(iter(vals.keys()))], **kwargs)
Expand Down

0 comments on commit 34c5dab

Please sign in to comment.