Skip to content

Commit e3724b6

Browse files
FIX-#7640: Respect AutoSwitchBackend.disable() in init. (#7641)
I introduced a subtle bug that caused some cases of `__init__` to not respect `AutoSwitchBackend.disable()` here: https://github.com/modin-project/modin/blob/44ee0178b6ed66553fdc8bc43e4cc9e31c8cf92d/modin/core/storage_formats/pandas/query_compiler_caster.py#L1056 That should be `< 2` as it was before; otherwise `__init__` from a non-modin input (e.g. the dict in this case) will auto-switch regardless of the value of `AutoSwitchBackend`. Resolves #7640 Signed-off-by: sfc-gh-mvashishtha <mahesh.vashishtha@snowflake.com>
1 parent 44ee017 commit e3724b6

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

modin/core/storage_formats/pandas/query_compiler_caster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,10 @@ def register_query_compilers(arg):
10501050
input_qc_for_pre_op_switch = input_query_compilers[0]
10511051
input_backend = input_qc_for_pre_op_switch.get_backend()
10521052

1053-
# Skip the casting code if there's only one input backend and either
1053+
# Skip the casting code if there are < 2 input backends and either
10541054
# auto-switching is disabled or the inputs are pinned to the input
10551055
# backend.
1056-
if len(input_backends) == 1 and (
1056+
if len(input_backends) < 2 and (
10571057
not AutoSwitchBackend.get() or pin_target_backend is not None
10581058
):
10591059
f_to_apply = _get_extension_for_method(

modin/tests/pandas/native_df_interoperability/test_compiler_caster.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,28 @@ def test___init___with_in_memory_data_uses_native_query_compiler(
14161416
):
14171417
assert data_class(*args, **kwargs).get_backend() == expected_backend
14181418

1419+
@pytest.mark.parametrize("data_class", [pd.DataFrame, pd.Series])
1420+
@backend_test_context(
1421+
test_backend="Big_Data_Cloud", choices=("Big_Data_Cloud", "Small_Data_Local")
1422+
)
1423+
@pytest.mark.parametrize(
1424+
"auto_switch_backend,expected_backend",
1425+
[
1426+
(True, "Small_Data_Local"),
1427+
(False, "Big_Data_Cloud"),
1428+
],
1429+
)
1430+
def test_auto_switch_backend_disabled_prevents___init__auto_switch(
1431+
self, auto_switch_backend, expected_backend, data_class
1432+
):
1433+
register_function_for_pre_op_switch(
1434+
class_name=data_class.__name__,
1435+
method="__init__",
1436+
backend="Big_Data_Cloud",
1437+
)
1438+
with config_context(AutoSwitchBackend=auto_switch_backend):
1439+
assert data_class([1, 2, 3]).get_backend() == expected_backend
1440+
14191441
@pytest.mark.parametrize(
14201442
"num_input_rows, expected_backend",
14211443
[

0 commit comments

Comments
 (0)