Skip to content

Commit afb69d7

Browse files
committed
More comments to address
1 parent ff3ae9c commit afb69d7

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

modin/core/storage_formats/pandas/query_compiler_caster.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ def cast_args(*args: Tuple, **kwargs: Dict) -> Any:
256256

257257
def arg_needs_casting(arg):
258258
current_qc_type = type(current_qc)
259-
return isinstance(arg, BaseQueryCompiler) and not isinstance(arg, current_qc_type)
259+
return isinstance(arg, BaseQueryCompiler) and not isinstance(
260+
arg, current_qc_type
261+
)
260262

261263
def register_query_compilers(arg):
262264
if not arg_needs_casting(arg):
@@ -270,7 +272,9 @@ def cast_to_qc(arg):
270272
qc_type = calculator.calculate()
271273
if qc_type is None or qc_type is type(arg):
272274
return arg
273-
return qc_type.from_pandas(arg.to_pandas(), data_cls=calculator.result_data_cls())
275+
return qc_type.from_pandas(
276+
arg.to_pandas(), data_cls=calculator.result_data_cls()
277+
)
274278

275279
if isinstance(current_qc, BaseQueryCompiler):
276280
visit_nested_args(kwargs, register_query_compilers)
@@ -279,19 +283,19 @@ def cast_to_qc(arg):
279283
args = visit_nested_args(args, cast_to_qc)
280284
kwargs = visit_nested_args(kwargs, cast_to_qc)
281285

282-
qc = calculator.calculate()
286+
result_qc_type = calculator.calculate()
283287

284-
if qc is None or qc is type(current_qc):
288+
if result_qc_type is None or result_qc_type is type(current_qc):
285289
return obj(*args, **kwargs)
286290

287291
# we need to cast current_qc to a new query compiler,
288292
# then lookup the same function on the new query compiler
289293
# we need to also drop the first argument to the original
290294
# args since it references self on the original argument
291295
# call
292-
if qc != current_qc:
296+
if result_qc_type != current_qc:
293297
data_cls = current_qc._modin_frame
294-
new_qc = qc.from_pandas(current_qc.to_pandas(), data_cls)
298+
new_qc = result_qc_type.from_pandas(current_qc.to_pandas(), data_cls)
295299
obj_new = getattr(new_qc, obj.__name__)
296300
return obj_new(*args[1:], **kwargs)
297301

modin/tests/pandas/native_df_interoperability/test_compiler_caster.py

-28
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
class CloudQC(NativeQueryCompiler):
2626
"Represents a cloud-hosted query compiler"
2727

28-
def __init__(self, pandas_frame):
29-
self._modin_frame = pandas_frame
30-
super().__init__(pandas_frame)
31-
3228
def qc_engine_switch_cost(self, other_qc_cls):
3329
return {
3430
CloudQC: QCCoercionCost.COST_ZERO,
@@ -42,10 +38,6 @@ def qc_engine_switch_cost(self, other_qc_cls):
4238
class ClusterQC(NativeQueryCompiler):
4339
"Represents a local network cluster query compiler"
4440

45-
def __init__(self, pandas_frame):
46-
self._modin_frame = pandas_frame
47-
super().__init__(pandas_frame)
48-
4941
def qc_engine_switch_cost(self, other_qc_cls):
5042
return {
5143
CloudQC: QCCoercionCost.COST_MEDIUM,
@@ -59,10 +51,6 @@ def qc_engine_switch_cost(self, other_qc_cls):
5951
class LocalMachineQC(NativeQueryCompiler):
6052
"Represents a local machine query compiler"
6153

62-
def __init__(self, pandas_frame):
63-
self._modin_frame = pandas_frame
64-
super().__init__(pandas_frame)
65-
6654
def qc_engine_switch_cost(self, other_qc_cls):
6755
return {
6856
CloudQC: QCCoercionCost.COST_MEDIUM,
@@ -75,10 +63,6 @@ def qc_engine_switch_cost(self, other_qc_cls):
7563
class PicoQC(NativeQueryCompiler):
7664
"Represents a query compiler with very few resources"
7765

78-
def __init__(self, pandas_frame):
79-
self._modin_frame = pandas_frame
80-
super().__init__(pandas_frame)
81-
8266
def qc_engine_switch_cost(self, other_qc_cls):
8367
return {
8468
CloudQC: QCCoercionCost.COST_LOW,
@@ -91,10 +75,6 @@ def qc_engine_switch_cost(self, other_qc_cls):
9175
class AdversarialQC(NativeQueryCompiler):
9276
"Represents a query compiler which returns non-sensical costs"
9377

94-
def __init__(self, pandas_frame):
95-
self._modin_frame = pandas_frame
96-
super().__init__(pandas_frame)
97-
9878
def qc_engine_switch_cost(self, other_qc_cls):
9979
return {
10080
CloudQC: -1000,
@@ -106,18 +86,10 @@ def qc_engine_switch_cost(self, other_qc_cls):
10686
class DefaultQC(NativeQueryCompiler):
10787
"Represents a query compiler with no costing information"
10888

109-
def __init__(self, pandas_frame):
110-
self._modin_frame = pandas_frame
111-
super().__init__(pandas_frame)
112-
11389

11490
class DefaultQC2(NativeQueryCompiler):
11591
"Represents a query compiler with no costing information, but different."
11692

117-
def __init__(self, pandas_frame):
118-
self._modin_frame = pandas_frame
119-
super().__init__(pandas_frame)
120-
12193

12294
@pytest.fixture()
12395
def cloud_df():

0 commit comments

Comments
 (0)