|
16 | 16 |
|
17 | 17 | import os
|
18 | 18 | from typing import cast, Optional, Union
|
| 19 | +import warnings |
19 | 20 |
|
20 | 21 | import IPython.display as ipy_display
|
21 | 22 | import pandas as pd
|
22 | 23 | import requests
|
23 | 24 |
|
24 | 25 | from bigframes import clients
|
25 | 26 | import bigframes.dataframe
|
| 27 | +import bigframes.exceptions as bfe |
26 | 28 | from bigframes.operations import base
|
27 | 29 | import bigframes.operations as ops
|
28 | 30 | import bigframes.series
|
@@ -166,6 +168,30 @@ def _get_runtime(
|
166 | 168 |
|
167 | 169 | return s._apply_unary_op(ops.ObjGetAccessUrl(mode=mode))
|
168 | 170 |
|
| 171 | + def _df_apply_udf( |
| 172 | + self, df: bigframes.dataframe.DataFrame, udf |
| 173 | + ) -> bigframes.series.Series: |
| 174 | + # Catch and rethrow function axis=1 warning to be more user-friendly. |
| 175 | + with warnings.catch_warnings(record=True) as catched_warnings: |
| 176 | + s = df.apply(udf, axis=1) |
| 177 | + for w in catched_warnings: |
| 178 | + if isinstance(w.message, bfe.FunctionAxisOnePreviewWarning): |
| 179 | + warnings.warn( |
| 180 | + "Blob Functions use bigframes DataFrame Managed function with axis=1 senario, which is a preview feature.", |
| 181 | + category=w.category, |
| 182 | + stacklevel=2, |
| 183 | + ) |
| 184 | + else: |
| 185 | + warnings.warn_explicit( |
| 186 | + message=w.message, |
| 187 | + category=w.category, |
| 188 | + filename=w.filename, |
| 189 | + lineno=w.lineno, |
| 190 | + source=w.source, |
| 191 | + ) |
| 192 | + |
| 193 | + return s |
| 194 | + |
169 | 195 | def read_url(self) -> bigframes.series.Series:
|
170 | 196 | """Retrieve the read URL of the Blob.
|
171 | 197 |
|
@@ -346,7 +372,7 @@ def image_blur(
|
346 | 372 |
|
347 | 373 | df["ksize_x"], df["ksize_y"] = ksize
|
348 | 374 | df["ext"] = ext # type: ignore
|
349 |
| - res = df.apply(image_blur_udf, axis=1) |
| 375 | + res = self._df_apply_udf(df, image_blur_udf) |
350 | 376 |
|
351 | 377 | return res
|
352 | 378 |
|
@@ -375,7 +401,7 @@ def image_blur(
|
375 | 401 | df["ksize_x"], df["ksize_y"] = ksize
|
376 | 402 | df["ext"] = ext # type: ignore
|
377 | 403 |
|
378 |
| - res = df.apply(image_blur_udf, axis=1) |
| 404 | + res = self._df_apply_udf(df, image_blur_udf) |
379 | 405 | res.cache() # to execute the udf
|
380 | 406 |
|
381 | 407 | self._add_to_cleanup_set(image_blur_udf)
|
@@ -443,7 +469,7 @@ def image_resize(
|
443 | 469 | df["dsize_x"], df["dsizye_y"] = dsize
|
444 | 470 | df["fx"], df["fy"] = fx, fy
|
445 | 471 | df["ext"] = ext # type: ignore
|
446 |
| - res = df.apply(image_resize_udf, axis=1) |
| 472 | + res = self._df_apply_udf(df, image_resize_udf) |
447 | 473 |
|
448 | 474 | return res
|
449 | 475 |
|
@@ -473,7 +499,7 @@ def image_resize(
|
473 | 499 | df["fx"], df["fy"] = fx, fy
|
474 | 500 | df["ext"] = ext # type: ignore
|
475 | 501 |
|
476 |
| - res = df.apply(image_resize_udf, axis=1) |
| 502 | + res = self._df_apply_udf(df, image_resize_udf) |
477 | 503 | res.cache() # to execute the udf
|
478 | 504 |
|
479 | 505 | self._add_to_cleanup_set(image_resize_udf)
|
@@ -535,7 +561,7 @@ def image_normalize(
|
535 | 561 | df["beta"] = beta
|
536 | 562 | df["norm_type"] = norm_type
|
537 | 563 | df["ext"] = ext # type: ignore
|
538 |
| - res = df.apply(image_normalize_udf, axis=1) |
| 564 | + res = self._df_apply_udf(df, image_normalize_udf) |
539 | 565 |
|
540 | 566 | return res
|
541 | 567 |
|
@@ -566,7 +592,7 @@ def image_normalize(
|
566 | 592 | df["norm_type"] = norm_type
|
567 | 593 | df["ext"] = ext # type: ignore
|
568 | 594 |
|
569 |
| - res = df.apply(image_normalize_udf, axis=1) |
| 595 | + res = self._df_apply_udf(df, image_normalize_udf) |
570 | 596 | res.cache() # to execute the udf
|
571 | 597 |
|
572 | 598 | self._add_to_cleanup_set(image_normalize_udf)
|
@@ -681,7 +707,7 @@ def pdf_chunk(
|
681 | 707 | df["chunk_size"] = chunk_size
|
682 | 708 | df["overlap_size"] = overlap_size
|
683 | 709 |
|
684 |
| - res = df.apply(pdf_chunk_udf, axis=1) |
| 710 | + res = self._df_apply_udf(df, pdf_chunk_udf) |
685 | 711 |
|
686 | 712 | res_array = bbq.json_extract_string_array(res)
|
687 | 713 |
|
|
0 commit comments