Skip to content

Commit 31e5af6

Browse files
committed
More doc fixes
1 parent 110fe64 commit 31e5af6

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

modin/core/storage_formats/pandas/query_compiler_caster.py

+51-13
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@
3636

3737

3838
class QueryCompilerCasterCalculator:
39-
39+
"""
40+
Calculate which QueryCompiler should be used for an operation.
41+
42+
Given a set of QueryCompilers; containing various data, determine
43+
which query compiler everything should be cast to which minimizes
44+
the cost of casting, or coercion. Use the aggregate sum of coercion
45+
to determine overall cost.
46+
"""
47+
4048
def __init__(self):
4149
self._caster_costing_map = {}
4250
self._data_cls_map = {}
@@ -45,6 +53,13 @@ def __init__(self):
4553
self._result_type = None
4654

4755
def add_query_compiler(self, query_compiler):
56+
"""
57+
Add a query compiler to be considered for casting.
58+
59+
Parameters
60+
----------
61+
query_compiler : QueryCompiler
62+
"""
4863
if isinstance(query_compiler, type):
4964
# class
5065
qc_type = query_compiler
@@ -56,6 +71,14 @@ def add_query_compiler(self, query_compiler):
5671
self._qc_cls_list.append(qc_type)
5772

5873
def calculate(self):
74+
"""
75+
Calculate which query compiler we should cast to.
76+
77+
Returns
78+
-------
79+
type
80+
QueryCompiler class which should be used for the operation.
81+
"""
5982
if self._result_type is not None:
6083
return self._result_type
6184
if len(self._qc_cls_list) == 1:
@@ -79,6 +102,14 @@ def calculate(self):
79102
return self._result_type
80103

81104
def _add_cost_data(self, costs: dict):
105+
"""
106+
Add the cost data to the calculator.
107+
108+
Parameters
109+
----------
110+
costs : dict
111+
Dictionary of query compiler classes to costs.
112+
"""
82113
for k, v in costs.items():
83114
# filter out any extranious query compilers not in this operation
84115
if k in self._qc_cls_list:
@@ -91,6 +122,14 @@ def _add_cost_data(self, costs: dict):
91122
)
92123

93124
def result_data_frame(self):
125+
"""
126+
Return the data frame associated with the calculated query compiler.
127+
128+
Returns
129+
-------
130+
DataFrame object
131+
DataFrame object associated with the preferred query compiler.
132+
"""
94133
qc_type = self.calculate()
95134
return self._data_cls_map[qc_type]
96135

@@ -119,38 +158,37 @@ def __init_subclass__(
119158
apply_argument_cast(cls)
120159

121160

122-
def visit_nested_args(arguments, current_qc: BaseQueryCompiler, fn: callable):
161+
def visit_nested_args(arguments, fn: callable):
123162
"""
124-
Cast all arguments in nested fashion to current query compiler.
125-
163+
Visit each argument recursively, calling fn on each one.
164+
126165
Parameters
127166
----------
128167
arguments : tuple or dict
129-
current_qc : BaseQueryCompiler
168+
fn : Callable to apply to matching arguments
130169
131170
Returns
132171
-------
133172
tuple or dict
134173
Returns args and kwargs with all query compilers casted to current_qc.
135174
"""
136-
137175
imutable_types = (FrozenList, tuple)
138176
if isinstance(arguments, imutable_types):
139177
args_type = type(arguments)
140178
arguments = list(arguments)
141-
arguments = visit_nested_args(arguments, current_qc, fn)
179+
arguments = visit_nested_args(arguments, fn)
142180

143181
return args_type(arguments)
144182
if isinstance(arguments, list):
145183
for i in range(len(arguments)):
146184
if isinstance(arguments[i], (list, dict)):
147-
visit_nested_args(arguments[i], current_qc, fn)
185+
visit_nested_args(arguments[i], fn)
148186
else:
149187
arguments[i] = fn(arguments[i])
150188
elif isinstance(arguments, dict):
151189
for key in arguments:
152190
if isinstance(arguments[key], (list, dict)):
153-
visit_nested_args(arguments[key], current_qc, fn)
191+
visit_nested_args(arguments[key], fn)
154192
else:
155193
arguments[key] = fn(arguments[key])
156194
return arguments
@@ -239,11 +277,11 @@ def cast_to_qc(arg):
239277
return result
240278

241279
if isinstance(current_qc, BaseQueryCompiler):
242-
visit_nested_args(kwargs, current_qc, register_query_compilers)
243-
visit_nested_args(args, current_qc, register_query_compilers)
280+
visit_nested_args(kwargs, register_query_compilers)
281+
visit_nested_args(args, register_query_compilers)
244282

245-
args = visit_nested_args(args, current_qc, cast_to_qc)
246-
kwargs = visit_nested_args(kwargs, current_qc, cast_to_qc)
283+
args = visit_nested_args(args, cast_to_qc)
284+
kwargs = visit_nested_args(kwargs, cast_to_qc)
247285

248286
qc = calculator.calculate()
249287

0 commit comments

Comments
 (0)