Skip to content

Commit cb308f7

Browse files
authored
Merge branch 'main' into jkew/emit-hybrid-metrics
2 parents b2cdd2f + 837fb95 commit cb308f7

File tree

7 files changed

+76
-22
lines changed

7 files changed

+76
-22
lines changed

modin/core/storage_formats/pandas/query_compiler_caster.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ def get_backend(self) -> str:
222222
pass
223223

224224
@abstractmethod
225-
def set_backend(self, backend: str, inplace: bool) -> Optional[Self]:
225+
def set_backend(
226+
self, backend: str, inplace: bool, *, switch_operation: Optional[str] = None
227+
) -> Optional[Self]:
226228
"""
227229
Set the backend of this object.
228230
@@ -231,9 +233,13 @@ def set_backend(self, backend: str, inplace: bool) -> Optional[Self]:
231233
backend : str
232234
The new backend.
233235
234-
inplace : bool, default False
236+
inplace : bool, default: False
235237
Whether to update the object in place.
236238
239+
switch_operation : Optional[str], default: None
240+
The name of the operation that triggered the set_backend call.
241+
Internal argument used for displaying progress bar information.
242+
237243
Returns
238244
-------
239245
Optional[Self]
@@ -463,7 +469,11 @@ def cast_to_qc(arg: Any) -> Any:
463469
and arg.get_backend() != result_backend
464470
):
465471
return arg
466-
arg.set_backend(result_backend, inplace=True)
472+
arg.set_backend(
473+
result_backend,
474+
inplace=True,
475+
switch_operation=f"{class_of_wrapped_fn}.{function_name}",
476+
)
467477
return arg
468478

469479
return result_backend, cast_to_qc
@@ -538,7 +548,8 @@ def _maybe_switch_backend_post_op(
538548
class_of_wrapped_fn=class_of_wrapped_fn,
539549
function_name=function_name,
540550
arguments=arguments,
541-
)
551+
),
552+
switch_operation=f"{class_of_wrapped_fn}.{function_name}",
542553
)
543554
return result
544555

@@ -923,7 +934,9 @@ def cast_to_qc(arg):
923934
and arg.get_backend() != result_backend
924935
):
925936
return arg
926-
cast = arg.set_backend(result_backend)
937+
cast = arg.set_backend(
938+
result_backend, switch_operation=f"{class_of_wrapped_fn}.{name}"
939+
)
927940
inplace_update_trackers.append(
928941
InplaceUpdateTracker(
929942
input_castable=arg,

modin/pandas/base.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4496,7 +4496,9 @@ def _set_backend_pinned(
44964496
return self
44974497

44984498
@doc(SET_BACKEND_DOC, class_name=__qualname__)
4499-
def set_backend(self, backend: str, inplace: bool = False) -> Optional[Self]:
4499+
def set_backend(
4500+
self, backend: str, inplace: bool = False, *, switch_operation: str = None
4501+
) -> Optional[Self]:
45004502
# TODO(https://github.com/modin-project/modin/issues/7467): refactor
45014503
# to avoid this cyclic import in most places we do I/O, e.g. in
45024504
# modin/pandas/io.py
@@ -4506,16 +4508,24 @@ def set_backend(self, backend: str, inplace: bool = False) -> Optional[Self]:
45064508

45074509
progress_split_count = 2
45084510
progress_iter = iter(range(progress_split_count))
4509-
if Backend.normalize(backend) != self.get_backend():
4511+
self_backend = self.get_backend()
4512+
normalized_backend = Backend.normalize(backend)
4513+
if normalized_backend != self_backend:
45104514
try:
45114515
from tqdm.auto import trange
45124516

4513-
progress_iter = iter(
4514-
trange(
4515-
progress_split_count,
4516-
desc=f"Transferring data from {self.get_backend()} to {Backend.normalize(backend)} ...",
4517+
max_rows, max_cols = self._query_compiler._max_shape()
4518+
if switch_operation is None:
4519+
desc = (
4520+
f"Transferring data from {self_backend} to {normalized_backend}"
4521+
+ f" with max estimated shape {max_rows}x{max_cols}"
45174522
)
4518-
)
4523+
else:
4524+
desc = (
4525+
f"Transferring data from {self_backend} to {normalized_backend} for"
4526+
+ f" '{switch_operation}' with max estimated shape {max_rows}x{max_cols}"
4527+
)
4528+
progress_iter = iter(trange(progress_split_count, desc=desc))
45194529
except ImportError:
45204530
# Iterate over blank range(2) if tqdm is not installed
45214531
pass

modin/pandas/dataframe.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,8 +3360,16 @@ def __reduce__(self):
33603360
# Persistance support methods - END
33613361

33623362
@doc(SET_BACKEND_DOC, class_name=__qualname__)
3363-
def set_backend(self, backend: str, inplace: bool = False) -> Optional[Self]:
3364-
return super().set_backend(backend=backend, inplace=inplace)
3363+
def set_backend(
3364+
self,
3365+
backend: str,
3366+
inplace: bool = False,
3367+
*,
3368+
switch_operation: Optional[str] = None,
3369+
) -> Optional[Self]:
3370+
return super().set_backend(
3371+
backend=backend, inplace=inplace, switch_operation=switch_operation
3372+
)
33653373

33663374
move_to = set_backend
33673375

modin/pandas/groupby.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,19 @@ def _get_query_compiler(self) -> Optional[BaseQueryCompiler]:
166166
return None
167167

168168
@disable_logging
169-
@_inherit_docstrings(QueryCompilerCaster._get_query_compiler)
169+
@_inherit_docstrings(QueryCompilerCaster.get_backend)
170170
def get_backend(self) -> str:
171171
return self._df.get_backend()
172172

173173
@disable_logging
174-
@_inherit_docstrings(QueryCompilerCaster._get_query_compiler)
175-
def set_backend(self, backend: str, inplace: bool = False) -> Optional[Self]:
174+
@_inherit_docstrings(QueryCompilerCaster.set_backend)
175+
def set_backend(
176+
self,
177+
backend: str,
178+
inplace: bool = False,
179+
*,
180+
switch_operation: Optional[str] = None,
181+
) -> Optional[Self]:
176182
# TODO(https://github.com/modin-project/modin/issues/7544): implement
177183
# this method to support automatic pre-operation backend switch for
178184
# groupby methods.

modin/pandas/indexing.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from __future__ import annotations
3333

3434
import itertools
35-
from typing import TYPE_CHECKING, Union
35+
from typing import TYPE_CHECKING, Optional, Union
3636

3737
import numpy as np
3838
import pandas
@@ -53,6 +53,8 @@
5353
from .utils import is_scalar
5454

5555
if TYPE_CHECKING:
56+
from typing_extensions import Self
57+
5658
from modin.core.storage_formats import BaseQueryCompiler
5759

5860

@@ -333,8 +335,12 @@ def _set_backend_pinned(self, pinned: bool, inplace: bool = False):
333335

334336
@disable_logging
335337
@_inherit_docstrings(QueryCompilerCaster.set_backend)
336-
def set_backend(self, backend, inplace: bool = False):
337-
result = type(self)(self.df.set_backend(backend))
338+
def set_backend(
339+
self, backend, inplace: bool = False, *, switch_operation: Optional[str] = None
340+
) -> Optional[Self]:
341+
result = type(self)(
342+
self.df.set_backend(backend, switch_operation=switch_operation)
343+
)
338344
if inplace:
339345
result._copy_into(self)
340346
return None

modin/pandas/series.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,8 +2872,16 @@ def __reduce__(self):
28722872
# Persistance support methods - END
28732873

28742874
@doc(SET_BACKEND_DOC, class_name=__qualname__)
2875-
def set_backend(self, backend: str, inplace: bool = False) -> Optional[Self]:
2876-
return super().set_backend(backend=backend, inplace=inplace)
2875+
def set_backend(
2876+
self,
2877+
backend: str,
2878+
inplace: bool = False,
2879+
*,
2880+
switch_operation: Optional[str] = None,
2881+
) -> Optional[Self]:
2882+
return super().set_backend(
2883+
backend=backend, inplace=inplace, switch_operation=switch_operation
2884+
)
28772885

28782886
move_to = set_backend
28792887

modin/pandas/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
The name of the backend to set.
6565
inplace : bool, default: False
6666
Whether to modify this ``{class_name}`` in place.
67+
switch_operation : Optional[str], default: None
68+
The name of the operation that triggered the set_backend call.
69+
Internal argument used for displaying progress bar information.
6770
6871
Returns
6972
-------

0 commit comments

Comments
 (0)