@@ -193,20 +193,6 @@ def _df_apply_udf(
193193
194194 return s
195195
196- def _apply_udf_or_raise_error (
197- self , df : bigframes .dataframe .DataFrame , udf , operation_name : str
198- ) -> bigframes .series .Series :
199- """Helper to apply UDF with consistent error handling."""
200- try :
201- res = self ._df_apply_udf (df , udf )
202- except Exception as e :
203- raise RuntimeError (f"{ operation_name } UDF execution failed: { e } " ) from e
204-
205- if res is None :
206- raise RuntimeError (f"{ operation_name } returned None result" )
207-
208- return res
209-
210196 def read_url (self ) -> bigframes .series .Series :
211197 """Retrieve the read URL of the Blob.
212198
@@ -357,10 +343,6 @@ def exif(
357343
358344 Returns:
359345 bigframes.series.Series: JSON series of key-value pairs if verbose=False, or struct with status and content if verbose=True.
360-
361- Raises:
362- ValueError: If engine is not 'pillow'.
363- RuntimeError: If EXIF extraction fails or returns invalid structure.
364346 """
365347 if engine is None or engine .casefold () != "pillow" :
366348 raise ValueError ("Must specify the engine, supported value is 'pillow'." )
@@ -382,28 +364,22 @@ def exif(
382364 container_memory = container_memory ,
383365 ).udf ()
384366
385- res = self ._apply_udf_or_raise_error (df , exif_udf , "EXIF extraction" )
367+ res = self ._df_apply_udf (df , exif_udf )
386368
387369 if verbose :
388- try :
389- exif_content_series = bbq .parse_json (
390- res ._apply_unary_op (ops .JSONValue (json_path = "$.content" ))
391- ).rename ("exif_content" )
392- exif_status_series = res ._apply_unary_op (
393- ops .JSONValue (json_path = "$.status" )
394- )
395- except Exception as e :
396- raise RuntimeError (f"Failed to parse EXIF JSON result: { e } " ) from e
370+ exif_content_series = bbq .parse_json (
371+ res ._apply_unary_op (ops .JSONValue (json_path = "$.content" ))
372+ ).rename ("exif_content" )
373+ exif_status_series = res ._apply_unary_op (
374+ ops .JSONValue (json_path = "$.status" )
375+ )
397376 results_df = bpd .DataFrame (
398377 {"status" : exif_status_series , "content" : exif_content_series }
399378 )
400379 results_struct = bbq .struct (results_df ).rename ("exif_results" )
401380 return results_struct
402381 else :
403- try :
404- return bbq .parse_json (res )
405- except Exception as e :
406- raise RuntimeError (f"Failed to parse EXIF JSON result: { e } " ) from e
382+ return bbq .parse_json (res )
407383
408384 def image_blur (
409385 self ,
@@ -435,10 +411,6 @@ def image_blur(
435411
436412 Returns:
437413 bigframes.series.Series: blob Series if destination is GCS. Or bytes Series if destination is BQ. If verbose=True, returns struct with status and content.
438-
439- Raises:
440- ValueError: If engine is not 'opencv' or parameters are invalid.
441- RuntimeError: If image blur operation fails.
442414 """
443415 if engine is None or engine .casefold () != "opencv" :
444416 raise ValueError ("Must specify the engine, supported value is 'opencv'." )
@@ -465,7 +437,7 @@ def image_blur(
465437 df ["ksize_x" ], df ["ksize_y" ] = ksize
466438 df ["ext" ] = ext # type: ignore
467439 df ["verbose" ] = verbose
468- res = self ._apply_udf_or_raise_error (df , image_blur_udf , "Image blur" )
440+ res = self ._df_apply_udf (df , image_blur_udf )
469441
470442 if verbose :
471443 blurred_content_b64_series = res ._apply_unary_op (
@@ -514,7 +486,7 @@ def image_blur(
514486 df ["ext" ] = ext # type: ignore
515487 df ["verbose" ] = verbose
516488
517- res = self ._apply_udf_or_raise_error (df , image_blur_udf , "Image blur" )
489+ res = self ._df_apply_udf (df , image_blur_udf )
518490 res .cache () # to execute the udf
519491
520492 if verbose :
@@ -568,10 +540,6 @@ def image_resize(
568540
569541 Returns:
570542 bigframes.series.Series: blob Series if destination is GCS. Or bytes Series if destination is BQ. If verbose=True, returns struct with status and content.
571-
572- Raises:
573- ValueError: If engine is not 'opencv' or parameters are invalid.
574- RuntimeError: If image resize operation fails.
575543 """
576544 if engine is None or engine .casefold () != "opencv" :
577545 raise ValueError ("Must specify the engine, supported value is 'opencv'." )
@@ -602,11 +570,11 @@ def image_resize(
602570 container_memory = container_memory ,
603571 ).udf ()
604572
605- df ["dsize_x" ], df ["dsize_y " ] = dsize
573+ df ["dsize_x" ], df ["dsizye_y " ] = dsize
606574 df ["fx" ], df ["fy" ] = fx , fy
607575 df ["ext" ] = ext # type: ignore
608576 df ["verbose" ] = verbose
609- res = self ._apply_udf_or_raise_error (df , image_resize_udf , "Image resize" )
577+ res = self ._df_apply_udf (df , image_resize_udf )
610578
611579 if verbose :
612580 resized_content_b64_series = res ._apply_unary_op (
@@ -652,12 +620,12 @@ def image_resize(
652620 dst_rt = dst .blob .get_runtime_json_str (mode = "RW" )
653621
654622 df = df .join (dst_rt , how = "outer" )
655- df ["dsize_x" ], df ["dsize_y " ] = dsize
623+ df ["dsize_x" ], df ["dsizye_y " ] = dsize
656624 df ["fx" ], df ["fy" ] = fx , fy
657625 df ["ext" ] = ext # type: ignore
658626 df ["verbose" ] = verbose
659627
660- res = self ._apply_udf_or_raise_error (df , image_resize_udf , "Image resize" )
628+ res = self ._df_apply_udf (df , image_resize_udf )
661629 res .cache () # to execute the udf
662630
663631 if verbose :
@@ -711,10 +679,6 @@ def image_normalize(
711679
712680 Returns:
713681 bigframes.series.Series: blob Series if destination is GCS. Or bytes Series if destination is BQ. If verbose=True, returns struct with status and content.
714-
715- Raises:
716- ValueError: If engine is not 'opencv' or parameters are invalid.
717- RuntimeError: If image normalize operation fails.
718682 """
719683 if engine is None or engine .casefold () != "opencv" :
720684 raise ValueError ("Must specify the engine, supported value is 'opencv'." )
@@ -743,9 +707,7 @@ def image_normalize(
743707 df ["norm_type" ] = norm_type
744708 df ["ext" ] = ext # type: ignore
745709 df ["verbose" ] = verbose
746- res = self ._apply_udf_or_raise_error (
747- df , image_normalize_udf , "Image normalize"
748- )
710+ res = self ._df_apply_udf (df , image_normalize_udf )
749711
750712 if verbose :
751713 normalized_content_b64_series = res ._apply_unary_op (
@@ -796,7 +758,7 @@ def image_normalize(
796758 df ["ext" ] = ext # type: ignore
797759 df ["verbose" ] = verbose
798760
799- res = self ._apply_udf_or_raise_error (df , image_normalize_udf , "Image normalize" )
761+ res = self ._df_apply_udf (df , image_normalize_udf )
800762 res .cache () # to execute the udf
801763
802764 if verbose :
@@ -847,10 +809,6 @@ def pdf_extract(
847809 depend on the "verbose" parameter.
848810 Contains the extracted text from the PDF file.
849811 Includes error messages if verbosity is enabled.
850-
851- Raises:
852- ValueError: If engine is not 'pypdf'.
853- RuntimeError: If PDF extraction fails or returns invalid structure.
854812 """
855813 if engine is None or engine .casefold () != "pypdf" :
856814 raise ValueError ("Must specify the engine, supported value is 'pypdf'." )
@@ -872,29 +830,18 @@ def pdf_extract(
872830
873831 df = self .get_runtime_json_str (mode = "R" ).to_frame ()
874832 df ["verbose" ] = verbose
875-
876- res = self ._apply_udf_or_raise_error (df , pdf_extract_udf , "PDF extraction" )
833+ res = self ._df_apply_udf (df , pdf_extract_udf )
877834
878835 if verbose :
879- # Extract content with error handling
880- try :
881- content_series = res ._apply_unary_op (
882- ops .JSONValue (json_path = "$.content" )
883- )
884- except Exception as e :
885- raise RuntimeError (
886- f"Failed to extract content field from PDF result: { e } "
887- ) from e
888- try :
889- status_series = res ._apply_unary_op (ops .JSONValue (json_path = "$.status" ))
890- except Exception as e :
891- raise RuntimeError (
892- f"Failed to extract status field from PDF result: { e } "
893- ) from e
894-
895- res_df = bpd .DataFrame ({"status" : status_series , "content" : content_series })
896- struct_series = bbq .struct (res_df ).rename ("extracted_results" )
897- return struct_series
836+ extracted_content_series = res ._apply_unary_op (
837+ ops .JSONValue (json_path = "$.content" )
838+ )
839+ status_series = res ._apply_unary_op (ops .JSONValue (json_path = "$.status" ))
840+ results_df = bpd .DataFrame (
841+ {"status" : status_series , "content" : extracted_content_series }
842+ )
843+ results_struct = bbq .struct (results_df ).rename ("extracted_results" )
844+ return results_struct
898845 else :
899846 return res .rename ("extracted_content" )
900847
@@ -937,10 +884,6 @@ def pdf_chunk(
937884 depend on the "verbose" parameter.
938885 where each string is a chunk of text extracted from PDF.
939886 Includes error messages if verbosity is enabled.
940-
941- Raises:
942- ValueError: If engine is not 'pypdf'.
943- RuntimeError: If PDF chunking fails or returns invalid structure.
944887 """
945888 if engine is None or engine .casefold () != "pypdf" :
946889 raise ValueError ("Must specify the engine, supported value is 'pypdf'." )
@@ -972,25 +915,13 @@ def pdf_chunk(
972915 df ["overlap_size" ] = overlap_size
973916 df ["verbose" ] = verbose
974917
975- res = self ._apply_udf_or_raise_error (df , pdf_chunk_udf , "PDF chunking" )
976-
977- try :
978- content_series = bbq .json_extract_string_array (res , "$.content" )
979- except Exception as e :
980- raise RuntimeError (
981- f"Failed to extract content array from PDF chunk result: { e } "
982- ) from e
918+ res = self ._df_apply_udf (df , pdf_chunk_udf )
983919
984920 if verbose :
985- try :
986- status_series = res ._apply_unary_op (ops .JSONValue (json_path = "$.status" ))
987- except Exception as e :
988- raise RuntimeError (
989- f"Failed to extract status field from PDF chunk result: { e } "
990- ) from e
991-
921+ chunked_content_series = bbq .json_extract_string_array (res , "$.content" )
922+ status_series = res ._apply_unary_op (ops .JSONValue (json_path = "$.status" ))
992923 results_df = bpd .DataFrame (
993- {"status" : status_series , "content" : content_series }
924+ {"status" : status_series , "content" : chunked_content_series }
994925 )
995926 resultes_struct = bbq .struct (results_df ).rename ("chunked_results" )
996927 return resultes_struct
@@ -1031,10 +962,6 @@ def audio_transcribe(
1031962 depend on the "verbose" parameter.
1032963 Contains the transcribed text from the audio file.
1033964 Includes error messages if verbosity is enabled.
1034-
1035- Raises:
1036- ValueError: If engine is not 'bigquery'.
1037- RuntimeError: If the transcription result structure is invalid.
1038965 """
1039966 if engine .casefold () != "bigquery" :
1040967 raise ValueError ("Must specify the engine, supported value is 'bigquery'." )
@@ -1057,10 +984,6 @@ def audio_transcribe(
1057984 model_params = {"generationConfig" : {"temperature" : 0.0 }},
1058985 )
1059986
1060- # Validate that the result is not None
1061- if transcribed_results is None :
1062- raise RuntimeError ("Transcription returned None result" )
1063-
1064987 transcribed_content_series = transcribed_results .struct .field ("result" ).rename (
1065988 "transcribed_content"
1066989 )
0 commit comments