Skip to content

Commit

Permalink
Merge branch 'main' into b379743612-support-predict-explain-params
Browse files Browse the repository at this point in the history
  • Loading branch information
arwas11 authored Dec 20, 2024
2 parents 1311162 + c6ef52c commit 0971bf6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
python-version: "3.10"
- name: Install nox
run: |
python -m pip install --upgrade setuptools pip wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: Install nox
run: |
python -m pip install --upgrade setuptools pip wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: Install coverage
run: |
python -m pip install --upgrade setuptools pip wheel
Expand Down
14 changes: 12 additions & 2 deletions bigframes/core/compile/scalar_op_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,13 @@ def json_extract_string_array_op_impl(

# Blob Ops
@scalar_op_compiler.register_unary_op(ops.obj_fetch_metadata_op)
def obj_fetch_metadata_op_impl(x: ibis_types.Value):
return obj_fetch_metadata(obj_ref=x)
def obj_fetch_metadata_op_impl(obj_ref: ibis_types.Value):
return obj_fetch_metadata(obj_ref=obj_ref)


@scalar_op_compiler.register_unary_op(ops.ObjGetAccessUrl, pass_op=True)
def obj_get_access_url_op_impl(obj_ref: ibis_types.Value, op: ops.ObjGetAccessUrl):
return obj_get_access_url(obj_ref=obj_ref, mode=op.mode)


### Binary Ops
Expand Down Expand Up @@ -1917,3 +1922,8 @@ def obj_fetch_metadata(obj_ref: _OBJ_REF_IBIS_DTYPE) -> _OBJ_REF_IBIS_DTYPE: #
@ibis_udf.scalar.builtin(name="OBJ.MAKE_REF")
def obj_make_ref(uri: str, authorizer: str) -> _OBJ_REF_IBIS_DTYPE: # type: ignore
"""Make ObjectRef Struct from uri and connection."""


@ibis_udf.scalar.builtin(name="OBJ.GET_ACCESS_URL")
def obj_get_access_url(obj_ref: _OBJ_REF_IBIS_DTYPE, mode: ibis_dtypes.String) -> ibis_dtypes.JSON: # type: ignore
"""Get access url (as ObjectRefRumtime JSON) from ObjectRef."""
10 changes: 10 additions & 0 deletions bigframes/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,16 @@ def output_type(self, *input_types):
)


## Blob Ops
@dataclasses.dataclass(frozen=True)
class ObjGetAccessUrl(UnaryOp):
name: typing.ClassVar[str] = "obj_get_access_url"
mode: str # access mode, e.g. R read, W write, RW read & write

def output_type(self, *input_types):
return dtypes.JSON_DTYPE


# Binary Ops
fillna_op = create_binary_op(name="fillna", type_signature=op_typing.COERCE)
maximum_op = create_binary_op(name="maximum", type_signature=op_typing.COERCE)
Expand Down
31 changes: 28 additions & 3 deletions bigframes/operations/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

from __future__ import annotations

import bigframes
import IPython.display as ipy_display
import requests

from bigframes.operations import base
import bigframes.operations as ops
import bigframes.series


class BlobAccessor(base.SeriesMethods):
Expand All @@ -26,7 +29,7 @@ def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

def metadata(self):
def metadata(self) -> bigframes.series.Series:
"""Retrive the metadata of the Blob.
.. note::
Expand All @@ -37,7 +40,29 @@ def metadata(self):
details_json = self._apply_unary_op(ops.obj_fetch_metadata_op).struct.field(
"details"
)

import bigframes.bigquery as bbq

return bbq.json_extract(details_json, "$.gcs_metadata")

def display(self, n: int = 3):
"""Display the blob content in the IPython Notebook environment. Only works for image type now.
.. note::
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
Args:
n (int, default 3): number of sample blob objects to display.
"""
import bigframes.bigquery as bbq

s = bigframes.series.Series(self._block).head(n)

obj_ref_runtime = s._apply_unary_op(ops.ObjGetAccessUrl(mode="R"))
read_urls = bbq.json_extract(
obj_ref_runtime, json_path="$.access_urls.read_url"
)

for read_url in read_urls:
read_url = str(read_url).strip('"')
response = requests.get(read_url)
ipy_display.display(ipy_display.Image(response.content))
3 changes: 3 additions & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# Add templated files
# ----------------------------------------------------------------------------
templated_files = common.py_library(
default_python_version="3.10",
unit_test_python_versions=["3.9", "3.10", "3.11", "3.12"],
system_test_python_versions=["3.9", "3.11", "3.12"],
cov_level=35,
Expand All @@ -53,6 +54,8 @@
".kokoro/build.sh",
".kokoro/continuous/common.cfg",
".kokoro/presubmit/common.cfg",
# Temporary workaround to update docs job to use python 3.10
".github/workflows/docs.yml",
],
)

Expand Down

0 comments on commit 0971bf6

Please sign in to comment.