Skip to content

Commit 4d7d721

Browse files
committed
improve the message
1 parent 729f40b commit 4d7d721

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

bigframes/dataframe.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4828,11 +4828,19 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs):
48284828
# 3. The order of the columns in the dataframe must correspond
48294829
# to the order of the input params in the function.
48304830
udf_input_dtypes = func.udf_def.signature.bf_input_types
4831-
if len(udf_input_dtypes) != len(self.columns) + len(args):
4831+
if not args and len(udf_input_dtypes) != len(self.columns):
48324832
raise ValueError(
48334833
f"Parameter count mismatch: BigFrames BigQuery function"
4834-
f" (including the args) expected {len(udf_input_dtypes)}"
4835-
f" but received {len(self.columns) + len(args)}."
4834+
f" expected {len(udf_input_dtypes)} parameters but"
4835+
f" received {len(self.columns)} DataFrame columns."
4836+
)
4837+
if args and len(udf_input_dtypes) != len(self.columns) + len(args):
4838+
raise ValueError(
4839+
f"Parameter count mismatch: BigFrames BigQuery function"
4840+
f" expected {len(udf_input_dtypes)} parameters but"
4841+
f" received {len(self.columns) + len(args)} values"
4842+
f" ({len(self.columns)} DataFrame coulmns and"
4843+
f" {len(args)} args)."
48364844
)
48374845
end_slice = -len(args) if args else None
48384846
if udf_input_dtypes[:end_slice] != tuple(self.dtypes.to_list()):

tests/system/large/functions/test_managed_function.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,14 @@ def foo(x, y, z):
467467

468468
# Fails to apply on dataframe with incompatible number of columns.
469469
with pytest.raises(
470-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 2."
470+
ValueError,
471+
match="^Parameter count mismatch:.* expected 3 parameters but received 2 DataFrame.*",
471472
):
472473
bf_df[["Id", "Age"]].apply(foo, axis=1)
473474

474475
with pytest.raises(
475-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 4."
476+
ValueError,
477+
match="^Parameter count mismatch:.* expected 3 parameters but received 4 DataFrame.*",
476478
):
477479
bf_df.assign(Country="lalaland").apply(foo, axis=1)
478480

@@ -983,7 +985,8 @@ def the_sum(s1, s2, x):
983985

984986
# Fails to apply on dataframe with incompatible number of columns.
985987
with pytest.raises(
986-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 4."
988+
ValueError,
989+
match="^Parameter count mismatch:.* expected 3 parameters but received 4 values.*",
987990
):
988991
scalars_df[columns + ["float64_col"]].apply(the_sum_mf, axis=1, args=args1)
989992

tests/system/large/functions/test_remote_function.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,8 @@ def the_sum(s1, s2, x):
19581958

19591959
# Fails to apply on dataframe with incompatible number of columns.
19601960
with pytest.raises(
1961-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 4."
1961+
ValueError,
1962+
match="^Parameter count mismatch:.* expected 3 parameters but received 4 values.*",
19621963
):
19631964
scalars_df[columns].apply(
19641965
the_sum_mf,
@@ -2306,11 +2307,13 @@ def foo(x, y, z):
23062307

23072308
# Fails to apply on dataframe with incompatible number of columns
23082309
with pytest.raises(
2309-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 2."
2310+
ValueError,
2311+
match="^Parameter count mismatch:.* expected 3 parameters but received 2 DataFrame.*",
23102312
):
23112313
bf_df[["Id", "Age"]].apply(foo, axis=1)
23122314
with pytest.raises(
2313-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 4."
2315+
ValueError,
2316+
match="^Parameter count mismatch:.* expected 3 parameters but received 4 DataFrame.*",
23142317
):
23152318
bf_df.assign(Country="lalaland").apply(foo, axis=1)
23162319

@@ -2388,11 +2391,13 @@ def foo(x, y, z):
23882391

23892392
# Fails to apply on dataframe with incompatible number of columns
23902393
with pytest.raises(
2391-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 2."
2394+
ValueError,
2395+
match="^Parameter count mismatch:.* expected 3 parameters but received 2 DataFrame.*",
23922396
):
23932397
bf_df[["Id", "Age"]].apply(foo, axis=1)
23942398
with pytest.raises(
2395-
ValueError, match="^Parameter count mismatch:.* expected 3 but received 4."
2399+
ValueError,
2400+
match="^Parameter count mismatch:.* expected 3 parameters but received 4 DataFrame.*",
23962401
):
23972402
bf_df.assign(Country="lalaland").apply(foo, axis=1)
23982403

@@ -2460,11 +2465,13 @@ def foo(x):
24602465

24612466
# Fails to apply on dataframe with incompatible number of columns
24622467
with pytest.raises(
2463-
ValueError, match="^Parameter count mismatch:.* expected 1 but received 0."
2468+
ValueError,
2469+
match="^Parameter count mismatch:.* expected 1 parameters but received 0 DataFrame.*",
24642470
):
24652471
bf_df[[]].apply(foo, axis=1)
24662472
with pytest.raises(
2467-
ValueError, match="^Parameter count mismatch:.* expected 1 but received 2."
2473+
ValueError,
2474+
match="^Parameter count mismatch:.* expected 1 parameters but received 2 DataFrame.*",
24682475
):
24692476
bf_df.assign(Country="lalaland").apply(foo, axis=1)
24702477

0 commit comments

Comments
 (0)