Skip to content

Commit b56d211

Browse files
committed
add preview doc and warning
1 parent e7d3a1c commit b56d211

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

bigframes/bigquery/_operations/json.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,26 @@
2323

2424
from typing import Any, cast, Optional, Sequence, Tuple, Union
2525

26+
import bigframes.core.utils as utils
2627
import bigframes.dtypes
2728
import bigframes.operations as ops
2829
import bigframes.series as series
2930

3031
from . import array
3132

3233

34+
@utils.preview(name="The JSON-related API `json_set`")
3335
def json_set(
3436
input: series.Series,
3537
json_path_value_pairs: Sequence[Tuple[str, Any]],
3638
) -> series.Series:
3739
"""Produces a new JSON value within a Series by inserting or replacing values at
3840
specified paths.
3941
42+
.. warning::
43+
The JSON-related API `parse_json` is in preview. Its behavior may change in
44+
future versions.
45+
4046
**Examples:**
4147
4248
>>> import bigframes.pandas as bpd
@@ -225,11 +231,16 @@ def json_extract_string_array(
225231
return array_series
226232

227233

234+
@utils.preview(name="The JSON-related API `parse_json`")
228235
def parse_json(
229236
input: series.Series,
230237
) -> series.Series:
231238
"""Converts a series with a JSON-formatted STRING value to a JSON value.
232239
240+
.. warning::
241+
The JSON-related API `parse_json` is in preview. Its behavior may change in
242+
future versions.
243+
233244
**Examples:**
234245
235246
>>> import bigframes.pandas as bpd

bigframes/core/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import functools
1415
import re
1516
import typing
1617
from typing import Hashable, Iterable, List
18+
import warnings
1719

1820
import bigframes_vendored.pandas.io.common as vendored_pandas_io_common
1921
import pandas as pd
2022
import typing_extensions
2123

24+
import bigframes.exceptions as exc
25+
2226
UNNAMED_COLUMN_ID = "bigframes_unnamed_column"
2327
UNNAMED_INDEX_ID = "bigframes_unnamed_index"
2428

@@ -164,3 +168,24 @@ def merge_column_labels(
164168
result_labels.append(col_label)
165169

166170
return pd.Index(result_labels)
171+
172+
173+
def warn_preview(msg=""):
174+
"""Warn a preview API."""
175+
warnings.warn(msg, exc.PreviewWarning)
176+
177+
178+
def preview(*, name: str):
179+
"""Decorate to warn of a preview API."""
180+
181+
def decorator(func):
182+
msg = f"{name} is in preview. Its behavior may change in future versions."
183+
184+
@functools.wraps(func)
185+
def wrapper(*args, **kwargs):
186+
warn_preview(msg=msg)
187+
return func(*args, **kwargs)
188+
189+
return wrapper
190+
191+
return decorator

0 commit comments

Comments
 (0)