Skip to content

Commit e4c9c81

Browse files
committed
chore: reformat/linting
1 parent 4912949 commit e4c9c81

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

packages/bigframes/tests/system/small/ml/test_cluster.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,16 @@ def sort_and_abs_categorical(val):
151151
# Accept BOTH python lists AND numpy arrays
152152
if isinstance(val, (list, np.ndarray)) and len(val) > 0:
153153
# Take abs of value first, then sort
154-
processed = [{"category": x["category"], "value": abs(x["value"])} for x in val]
154+
processed = [
155+
{"category": x["category"], "value": abs(x["value"])} for x in val
156+
]
155157
return sorted(processed, key=lambda x: x["category"])
156158
return val
157159

158-
159160
result["numerical_value"] = result["numerical_value"].abs()
160-
result["categorical_value"] = result["categorical_value"].apply(sort_and_abs_categorical)
161+
result["categorical_value"] = result["categorical_value"].apply(
162+
sort_and_abs_categorical
163+
)
161164

162165
expected = (
163166
pd.DataFrame(
@@ -216,16 +219,18 @@ def sort_and_abs_categorical(val):
216219
.sort_values(["centroid_id", "feature"])
217220
.reset_index(drop=True)
218221
)
219-
222+
220223
# Sort and sign flip expected values to match the output of the model.
221224
expected["numerical_value"] = expected["numerical_value"].abs()
222-
expected["categorical_value"] = expected["categorical_value"].apply(sort_and_abs_categorical)
225+
expected["categorical_value"] = expected["categorical_value"].apply(
226+
sort_and_abs_categorical
227+
)
223228

224229
pd.testing.assert_frame_equal(
225230
result,
226231
expected,
227232
check_exact=False,
228-
rtol=0.1, # Keep or slightly increase if numerical drift persists
233+
rtol=0.1, # Keep or slightly increase if numerical drift persists
229234
# int64 Index by default in pandas versus Int64 (nullable) Index in BigQuery DataFrame
230235
check_index_type=False,
231236
check_dtype=False,

packages/bigframes/tests/system/small/ml/test_core.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_model_eval_with_data(penguins_bqml_linear_model, penguins_df_default_in
7979

8080
def test_model_centroids(penguins_bqml_kmeans_model: core.BqmlModel):
8181
result = penguins_bqml_kmeans_model.centroids().to_pandas()
82-
82+
8383
# FIX: Helper to ignore row order inside categorical_value lists
8484
# This prevents the test from failing if BQML returns [MALE, FEMALE] instead of [FEMALE, MALE]
8585
def sort_categorical(val):
@@ -88,10 +88,7 @@ def sort_categorical(val):
8888
return val
8989

9090
result["categorical_value"] = result["categorical_value"].apply(sort_categorical)
91-
92-
93-
94-
91+
9592
expected = (
9693
pd.DataFrame(
9794
{
@@ -151,7 +148,9 @@ def sort_categorical(val):
151148
)
152149

153150
# Sort expected values to match the output of the model.
154-
expected["categorical_value"] = expected["categorical_value"].apply(sort_categorical)
151+
expected["categorical_value"] = expected["categorical_value"].apply(
152+
sort_categorical
153+
)
155154

156155
pd.testing.assert_frame_equal(
157156
result,
@@ -179,13 +178,16 @@ def sort_and_abs_categorical(val):
179178
# Accept BOTH python lists AND numpy arrays
180179
if isinstance(val, (list, np.ndarray)) and len(val) > 0:
181180
# Take abs of value first, then sort
182-
processed = [{"category": x["category"], "value": abs(x["value"])} for x in val]
181+
processed = [
182+
{"category": x["category"], "value": abs(x["value"])} for x in val
183+
]
183184
return sorted(processed, key=lambda x: x["category"])
184185
return val
185186

186-
187187
result["numerical_value"] = result["numerical_value"].abs()
188-
result["categorical_value"] = result["categorical_value"].apply(sort_and_abs_categorical)
188+
result["categorical_value"] = result["categorical_value"].apply(
189+
sort_and_abs_categorical
190+
)
189191

190192
expected = (
191193
pd.DataFrame(
@@ -248,7 +250,9 @@ def sort_and_abs_categorical(val):
248250

249251
# Sort and sign flip expected values to match the output of the model.
250252
expected["numerical_value"] = expected["numerical_value"].abs()
251-
expected["categorical_value"] = expected["categorical_value"].apply(sort_and_abs_categorical)
253+
expected["categorical_value"] = expected["categorical_value"].apply(
254+
sort_and_abs_categorical
255+
)
252256

253257
utils.assert_pandas_df_equal_pca_components(
254258
result,

packages/bigframes/tests/system/small/ml/test_decomposition.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,16 @@ def sort_and_abs_categorical(val):
112112
# Accept BOTH python lists AND numpy arrays
113113
if isinstance(val, (list, np.ndarray)) and len(val) > 0:
114114
# Take abs of value first, then sort
115-
processed = [{"category": x["category"], "value": abs(x["value"])} for x in val]
115+
processed = [
116+
{"category": x["category"], "value": abs(x["value"])} for x in val
117+
]
116118
return sorted(processed, key=lambda x: x["category"])
117119
return val
118120

119-
120121
result["numerical_value"] = result["numerical_value"].abs()
121-
result["categorical_value"] = result["categorical_value"].apply(sort_and_abs_categorical)
122+
result["categorical_value"] = result["categorical_value"].apply(
123+
sort_and_abs_categorical
124+
)
122125

123126
expected = (
124127
pd.DataFrame(
@@ -144,16 +147,28 @@ def sort_and_abs_categorical(val):
144147
],
145148
"categorical_value": [
146149
[
147-
{"category": "Gentoo penguin (Pygoscelis papua)", "value": 0.25068877125667804},
148-
{"category": "Adelie Penguin (Pygoscelis adeliae)", "value": -0.20622291900416198},
149-
{"category": "Chinstrap penguin (Pygoscelis antarctica)", "value": -0.030161149275185855},
150+
{
151+
"category": "Gentoo penguin (Pygoscelis papua)",
152+
"value": 0.25068877125667804,
153+
},
154+
{
155+
"category": "Adelie Penguin (Pygoscelis adeliae)",
156+
"value": -0.20622291900416198,
157+
},
158+
{
159+
"category": "Chinstrap penguin (Pygoscelis antarctica)",
160+
"value": -0.030161149275185855,
161+
},
150162
],
151163
[
152164
{"category": "Biscoe", "value": 0.19761120114410635},
153165
{"category": "Dream", "value": -0.11264736305259061},
154166
{"category": "Torgersen", "value": -0.07065913511418596},
155167
],
156-
[], [], [], [],
168+
[],
169+
[],
170+
[],
171+
[],
157172
[
158173
{"category": ".", "value": 0.0015916894448071784},
159174
{"category": "MALE", "value": 0.06869704739750442},
@@ -166,11 +181,12 @@ def sort_and_abs_categorical(val):
166181
.sort_values(["principal_component_id", "feature"])
167182
.reset_index(drop=True)
168183
)
169-
184+
170185
# Sort and sign flip expected values to match the output of the model.
171186
expected["numerical_value"] = expected["numerical_value"].abs()
172-
expected["categorical_value"] = expected["categorical_value"].apply(sort_and_abs_categorical)
173-
187+
expected["categorical_value"] = expected["categorical_value"].apply(
188+
sort_and_abs_categorical
189+
)
174190

175191
bigframes.testing.utils.assert_pandas_df_equal_pca_components(
176192
result,

0 commit comments

Comments
 (0)