Skip to content

Commit bbbbfce

Browse files
committed
Fix a more serious issue where the object was not being reset to the new query compiler
1 parent 3f0eb1c commit bbbbfce

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

modin/core/storage_formats/pandas/query_compiler_caster.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,17 @@ def cast_to_qc(arg):
290290
if qc is None or qc is type(current_qc):
291291
return obj(*args, **kwargs)
292292

293-
# we need to cast current_qc to a new query compiler
293+
# we need to cast current_qc to a new query compiler,
294+
# then lookup the same function on the new query compiler
295+
# we need to also drop the first argument to the original
296+
# args since it references self on the original argument
297+
# call
294298
if qc != current_qc:
295299
data_cls = current_qc._modin_frame
296-
return qc.from_pandas(current_qc.to_pandas(), data_cls)
297-
# need to find the new function for obj
300+
new_qc = qc.from_pandas(current_qc.to_pandas(), data_cls)
301+
obj_new = getattr(new_qc, obj.__name__)
302+
return obj_new(*args[1:], **kwargs)
303+
298304
return obj(*args, **kwargs)
299305

300306
return cast_args

modin/tests/pandas/native_df_interoperability/test_compiler_caster.py

+12
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,15 @@ def test_qc_default_self_cost(default_df, default2_df):
275275
assert (
276276
default_df.qc_engine_switch_cost(type(default_df)) is QCCoercionCost.COST_ZERO
277277
)
278+
279+
280+
def test_qc_casting_moved_data(pico_df, cloud_df):
281+
pico_df1 = pd.DataFrame(query_compiler=pico_df)
282+
cloud_df1 = pd.DataFrame(query_compiler=cloud_df)
283+
native_cdf2 = cloud_df1._to_pandas()
284+
native_pdf2 = pico_df1._to_pandas()
285+
expected = native_cdf2 + native_pdf2
286+
df1 = pico_df1 + cloud_df1
287+
df2 = cloud_df1 + pico_df1
288+
assert df1._to_pandas().equals(expected)
289+
assert df2._to_pandas().equals(expected)

0 commit comments

Comments
 (0)