1
-
1
+ # Licensed to Modin Development Team under one or more contributor license agreements.
2
+ # See the NOTICE file distributed with this work for additional information regarding
3
+ # copyright ownership. The Modin Development Team licenses this file to you under the
4
+ # Apache License, Version 2.0 (the "License"); you may not use this file except in
5
+ # compliance with the License. You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software distributed under
10
+ # the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific language
12
+ # governing permissions and limitations under the License.
2
13
3
14
import pandas
4
15
import pytest
7
18
8
19
9
20
class CloudQC (NativeQueryCompiler ):
10
- 'Represents a cloud-hosted query compiler'
21
+ "Represents a cloud-hosted query compiler"
22
+
11
23
def __init__ (self , pandas_frame ):
12
24
self ._modin_frame = pandas_frame
13
25
super ().__init__ (pandas_frame )
14
-
26
+
15
27
def qc_engine_switch_cost (self , other_qc ):
16
- return {CloudQC : QCCoercionCost .COST_ZERO ,
17
- ClusterQC : QCCoercionCost .COST_MEDIUM ,
18
- LocalMachineQC : QCCoercionCost .COST_HIGH ,
19
- PicoQC : QCCoercionCost .COST_IMPOSSIBLE }
28
+ return {
29
+ CloudQC : QCCoercionCost .COST_ZERO ,
30
+ ClusterQC : QCCoercionCost .COST_MEDIUM ,
31
+ LocalMachineQC : QCCoercionCost .COST_HIGH ,
32
+ PicoQC : QCCoercionCost .COST_IMPOSSIBLE ,
33
+ }
34
+
20
35
21
36
class ClusterQC (NativeQueryCompiler ):
22
- 'Represents a local network cluster query compiler'
37
+ "Represents a local network cluster query compiler"
38
+
23
39
def __init__ (self , pandas_frame ):
24
40
self ._modin_frame = pandas_frame
25
41
super ().__init__ (pandas_frame )
26
-
42
+
27
43
def qc_engine_switch_cost (self , other_qc ):
28
- return {CloudQC : QCCoercionCost .COST_MEDIUM ,
29
- ClusterQC : QCCoercionCost .COST_ZERO ,
30
- LocalMachineQC : QCCoercionCost .COST_MEDIUM ,
31
- PicoQC : QCCoercionCost .COST_HIGH }
32
-
44
+ return {
45
+ CloudQC : QCCoercionCost .COST_MEDIUM ,
46
+ ClusterQC : QCCoercionCost .COST_ZERO ,
47
+ LocalMachineQC : QCCoercionCost .COST_MEDIUM ,
48
+ PicoQC : QCCoercionCost .COST_HIGH ,
49
+ }
50
+
51
+
33
52
class LocalMachineQC (NativeQueryCompiler ):
34
- 'Represents a local machine query compiler'
53
+ "Represents a local machine query compiler"
54
+
35
55
def __init__ (self , pandas_frame ):
36
56
self ._modin_frame = pandas_frame
37
57
super ().__init__ (pandas_frame )
38
-
58
+
39
59
def qc_engine_switch_cost (self , other_qc ):
40
- return {CloudQC : QCCoercionCost .COST_MEDIUM ,
41
- ClusterQC : QCCoercionCost .COST_LOW ,
42
- LocalMachineQC : QCCoercionCost .COST_ZERO ,
43
- PicoQC : QCCoercionCost .COST_MEDIUM }
60
+ return {
61
+ CloudQC : QCCoercionCost .COST_MEDIUM ,
62
+ ClusterQC : QCCoercionCost .COST_LOW ,
63
+ LocalMachineQC : QCCoercionCost .COST_ZERO ,
64
+ PicoQC : QCCoercionCost .COST_MEDIUM ,
65
+ }
66
+
44
67
45
68
class PicoQC (NativeQueryCompiler ):
46
- 'Represents a query compiler with very few resources'
69
+ "Represents a query compiler with very few resources"
70
+
47
71
def __init__ (self , pandas_frame ):
48
72
self ._modin_frame = pandas_frame
49
73
super ().__init__ (pandas_frame )
50
-
74
+
51
75
def qc_engine_switch_cost (self , other_qc ):
52
- return {CloudQC : QCCoercionCost .COST_LOW ,
53
- ClusterQC : QCCoercionCost .COST_LOW ,
54
- LocalMachineQC : QCCoercionCost .COST_LOW ,
55
- PicoQC : QCCoercionCost .COST_ZERO }
76
+ return {
77
+ CloudQC : QCCoercionCost .COST_LOW ,
78
+ ClusterQC : QCCoercionCost .COST_LOW ,
79
+ LocalMachineQC : QCCoercionCost .COST_LOW ,
80
+ PicoQC : QCCoercionCost .COST_ZERO ,
81
+ }
82
+
56
83
57
84
@pytest .fixture ()
58
85
def cloud_df ():
59
86
return CloudQC (pandas .DataFrame ([0 , 1 , 2 ]))
60
87
88
+
61
89
@pytest .fixture ()
62
90
def cluster_df ():
63
91
return ClusterQC (pandas .DataFrame ([0 , 1 , 2 ]))
64
92
93
+
65
94
@pytest .fixture ()
66
95
def local_df ():
67
96
return LocalMachineQC (pandas .DataFrame ([0 , 1 , 2 ]))
68
97
98
+
69
99
@pytest .fixture ()
70
100
def pico_df ():
71
101
return PicoQC (pandas .DataFrame ([0 , 1 , 2 ]))
72
102
103
+
73
104
def test_two_same_qc_types_noop (pico_df ):
74
105
df3 = pico_df .concat (axis = 1 , other = pico_df )
75
- assert (type (df3 ) == type (pico_df ))
106
+ assert type (df3 ) is type (pico_df )
107
+
76
108
77
109
def test_two_two_qc_types_rhs (pico_df , cluster_df ):
78
110
df3 = pico_df .concat (axis = 1 , other = cluster_df )
79
- assert (type (df3 ) == type (cluster_df )) # should move to cluster
111
+ assert type (df3 ) is type (cluster_df ) # should move to cluster
112
+
80
113
81
114
def test_two_two_qc_types_lhs (pico_df , cluster_df ):
82
115
df3 = cluster_df .concat (axis = 1 , other = pico_df )
83
- assert (type (df3 ) == type (cluster_df )) # should move to cluster
116
+ assert type (df3 ) is type (cluster_df ) # should move to cluster
117
+
84
118
85
119
@pytest .mark .parametrize (
86
120
"df1, df2, df3, df4, result_type" ,
@@ -103,12 +137,15 @@ def test_mixed_dfs(df1, df2, df3, df4, result_type, request):
103
137
df3 = request .getfixturevalue (df3 )
104
138
df4 = request .getfixturevalue (df4 )
105
139
result = df1 .concat (axis = 1 , other = [df2 , df3 , df4 ])
106
- assert (type (result ) == result_type )
140
+ assert type (result ) is result_type
141
+
107
142
108
143
# This currently passes because we have no "max cost" associated
109
144
# with a particular QC, so we would move all data to the PicoQC
110
145
# As soon as we can represent "max-cost" the result of this operation
111
146
# should be to move all dfs to the CloudQC
112
147
def test_extreme_pico (pico_df , cloud_df ):
113
- result = cloud_df .concat (axis = 1 , other = [pico_df , pico_df , pico_df , pico_df , pico_df , pico_df , pico_df ])
114
- assert (type (result ) == PicoQC )
148
+ result = cloud_df .concat (
149
+ axis = 1 , other = [pico_df , pico_df , pico_df , pico_df , pico_df , pico_df , pico_df ]
150
+ )
151
+ assert type (result ) is PicoQC
0 commit comments