Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX-#7093: Make sure idxmax and idxmin can work with string columns #7193

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions modin/tests/pandas/dataframe/test_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ 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):
modin_df, pandas_df = pd.DataFrame(data), pandas.DataFrame(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
Loading