|
18 | 18 | import sys |
19 | 19 | import typing |
20 | 20 | from typing import cast, Optional, Set |
| 21 | +import warnings |
21 | 22 |
|
22 | 23 | import cloudpickle |
23 | 24 | import google.api_core.exceptions |
|
26 | 27 | import pandas |
27 | 28 | import pyarrow |
28 | 29 |
|
| 30 | +import bigframes.exceptions as bfe |
29 | 31 | import bigframes.formatting_helpers as bf_formatting |
30 | 32 | from bigframes.functions import function_typing |
31 | 33 |
|
@@ -61,21 +63,40 @@ def get_remote_function_locations(bq_location): |
61 | 63 |
|
62 | 64 |
|
63 | 65 | def _get_updated_package_requirements( |
64 | | - package_requirements=None, is_row_processor=False, capture_references=True |
| 66 | + package_requirements=None, |
| 67 | + is_row_processor=False, |
| 68 | + capture_references=True, |
| 69 | + ignore_package_version=False, |
65 | 70 | ): |
66 | 71 | requirements = [] |
67 | 72 | if capture_references: |
68 | 73 | requirements.append(f"cloudpickle=={cloudpickle.__version__}") |
69 | 74 |
|
70 | 75 | if is_row_processor: |
71 | | - # bigframes function will send an entire row of data as json, which |
72 | | - # would be converted to a pandas series and processed Ensure numpy |
73 | | - # versions match to avoid unpickling problems. See internal issue |
74 | | - # b/347934471. |
75 | | - requirements.append(f"numpy=={numpy.__version__}") |
76 | | - requirements.append(f"pandas=={pandas.__version__}") |
77 | | - requirements.append(f"pyarrow=={pyarrow.__version__}") |
78 | | - |
| 76 | + if ignore_package_version: |
| 77 | + # TODO(jialuo): Add back the version after b/410924784 is resolved. |
| 78 | + # Due to current limitations on the packages version in Python UDFs, |
| 79 | + # we use `ignore_package_version` to optionally omit the version for |
| 80 | + # managed functions only. |
| 81 | + msg = bfe.format_message( |
| 82 | + "numpy, pandas, and pyarrow versions in the function execution" |
| 83 | + " environment may not precisely match your local environment." |
| 84 | + ) |
| 85 | + warnings.warn(msg, category=bfe.FunctionPackageVersionWarning) |
| 86 | + requirements.append("pandas") |
| 87 | + requirements.append("pyarrow") |
| 88 | + requirements.append("numpy") |
| 89 | + else: |
| 90 | + # bigframes function will send an entire row of data as json, which |
| 91 | + # would be converted to a pandas series and processed Ensure numpy |
| 92 | + # versions match to avoid unpickling problems. See internal issue |
| 93 | + # b/347934471. |
| 94 | + requirements.append(f"pandas=={pandas.__version__}") |
| 95 | + requirements.append(f"pyarrow=={pyarrow.__version__}") |
| 96 | + requirements.append(f"numpy=={numpy.__version__}") |
| 97 | + |
| 98 | + # TODO(b/435023957): Fix the issue of potential duplicate package versions |
| 99 | + # when `package_requirements` also contains `pandas/pyarrow/numpy`. |
79 | 100 | if package_requirements: |
80 | 101 | requirements.extend(package_requirements) |
81 | 102 |
|
|
0 commit comments