GeezerVison is showing github.com — fix: suppress JSONDtypeWarning in Anywidget mode and clean up progres… · google/bigframes@e0d185a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bigframes/__init__.py +20-7Lines changed: 20 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | """BigQuery DataFrames provides a DataFrame API scaled by the BigQuery engine.""" | 16 | 16 |
| 17 | | -from bigframes._config import option_context, options | 18 | | -from bigframes._config.bigquery_options import BigQueryOptions | 19 | | -from bigframes.core.global_session import close_session, get_global_session | 20 | | -import bigframes.enums as enums | 21 | | -import bigframes.exceptions as exceptions | 22 | | -from bigframes.session import connect, Session | 23 | | -from bigframes.version import __version__ | | 17 | +import warnings | | 18 | + | | 19 | +# Suppress Python version support warnings from google-cloud libraries. | | 20 | +# These are particularly noisy in Colab which still uses Python 3.10. | | 21 | +warnings.filterwarnings( | | 22 | + "ignore", | | 23 | + category=FutureWarning, | | 24 | + message=".*Google will stop supporting.*Python.*", | | 25 | +) | | 26 | + | | 27 | +from bigframes._config import option_context, options # noqa: E402 | | 28 | +from bigframes._config.bigquery_options import BigQueryOptions # noqa: E402 | | 29 | +from bigframes.core.global_session import ( # noqa: E402 | | 30 | + close_session, | | 31 | + get_global_session, | | 32 | +) | | 33 | +import bigframes.enums as enums # noqa: E402 | | 34 | +import bigframes.exceptions as exceptions # noqa: E402 | | 35 | +from bigframes.session import connect, Session # noqa: E402 | | 36 | +from bigframes.version import __version__ # noqa: E402 | 24 | 37 |
| 25 | 38 | _MAGIC_NAMES = ["bqsql"] | 26 | 39 |
| |
Collapse file Copy file name to clipboardExpand all lines: bigframes/dataframe.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -332,7 +332,7 @@ def dtypes(self) -> pandas.Series: | 332 | 332 |
| 333 | 333 | @property | 334 | 334 | def columns(self) -> pandas.Index: | 335 | | - return self.dtypes.index | | 335 | + return self._block.column_labels | 336 | 336 |
| 337 | 337 | @columns.setter | 338 | 338 | def columns(self, labels: pandas.Index): | |
Collapse file Copy file name to clipboardExpand all lines: bigframes/display/anywidget.py +20-10Lines changed: 20 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | import threading | 24 | 24 | from typing import Any, Iterator, Optional | 25 | 25 | import uuid | | 26 | +import warnings | 26 | 27 |
| 27 | 28 | import pandas as pd | 28 | 29 |
| @@ -111,23 +112,32 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame): | 111 | 112 | self.page_size = initial_page_size | 112 | 113 | self.max_columns = initial_max_columns | 113 | 114 |
| 114 | | - # TODO(b/469861913): Nested columns from structs (e.g., 'struct_col.name') are not currently sortable. | 115 | | - # TODO(b/463754889): Support non-string column labels for sorting. | 116 | | - if all(isinstance(col, str) for col in dataframe.columns): | 117 | | - self.orderable_columns = [ | 118 | | - str(col_name) | 119 | | - for col_name, dtype in dataframe.dtypes.items() | 120 | | - if dtypes.is_orderable(dtype) | 121 | | - ] | 122 | | - else: | 123 | | - self.orderable_columns = [] | | 115 | + self.orderable_columns = self._get_orderable_columns(dataframe) | 124 | 116 |
| 125 | 117 | self._initial_load() | 126 | 118 |
| 127 | 119 | # Signals to the frontend that the initial data load is complete. | 128 | 120 | # Also used as a guard to prevent observers from firing during initialization. | 129 | 121 | self._initial_load_complete = True | 130 | 122 |
| | 123 | + def _get_orderable_columns( | | 124 | + self, dataframe: bigframes.dataframe.DataFrame | | 125 | + ) -> list[str]: | | 126 | + """Determine which columns can be used for client-side sorting.""" | | 127 | + # TODO(b/469861913): Nested columns from structs (e.g., 'struct_col.name') are not currently sortable. | | 128 | + # TODO(b/463754889): Support non-string column labels for sorting. | | 129 | + if not all(isinstance(col, str) for col in dataframe.columns): | | 130 | + return [] | | 131 | + | | 132 | + with warnings.catch_warnings(): | | 133 | + warnings.simplefilter("ignore", bigframes.exceptions.JSONDtypeWarning) | | 134 | + warnings.simplefilter("ignore", category=FutureWarning) | | 135 | + return [ | | 136 | + str(col_name) | | 137 | + for col_name, dtype in dataframe.dtypes.items() | | 138 | + if dtypes.is_orderable(dtype) | | 139 | + ] | | 140 | + | 131 | 141 | def _initial_load(self) -> None: | 132 | 142 | """Get initial data and row count.""" | 133 | 143 | # obtain the row counts | |
Collapse file Copy file name to clipboardExpand all lines: bigframes/display/html.py +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -363,7 +363,13 @@ def repr_mimebundle( | 363 | 363 |
| 364 | 364 | if opts.repr_mode == "anywidget": | 365 | 365 | try: | 366 | | - return get_anywidget_bundle(obj, include=include, exclude=exclude) | | 366 | + with bigframes.option_context("display.progress_bar", None): | | 367 | + with warnings.catch_warnings(): | | 368 | + warnings.simplefilter( | | 369 | + "ignore", category=bigframes.exceptions.JSONDtypeWarning | | 370 | + ) | | 371 | + warnings.simplefilter("ignore", category=FutureWarning) | | 372 | + return get_anywidget_bundle(obj, include=include, exclude=exclude) | 367 | 373 | except ImportError: | 368 | 374 | # Anywidget is an optional dependency, so warn rather than fail. | 369 | 375 | # TODO(shuowei): When Anywidget becomes the default for all repr modes, | |
Collapse file Copy file name to clipboardExpand all lines: bigframes/pandas/io/api.py +8-9Lines changed: 8 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -354,15 +354,14 @@ def _read_gbq_colab( | 354 | 354 | ) | 355 | 355 | _set_default_session_location_if_possible_deferred_query(create_query) | 356 | 356 | if not config.options.bigquery._session_started: | 357 | | - with warnings.catch_warnings(): | 358 | | - # Don't warning about Polars in SQL cell. | 359 | | - # Related to b/437090788. | 360 | | - try: | 361 | | - bigframes._importing.import_polars() | 362 | | - warnings.simplefilter("ignore", bigframes.exceptions.PreviewWarning) | 363 | | - config.options.bigquery.enable_polars_execution = True | 364 | | - except ImportError: | 365 | | - pass # don't fail if polars isn't available | | 357 | + # Don't warning about Polars in SQL cell. | | 358 | + # Related to b/437090788. | | 359 | + try: | | 360 | + bigframes._importing.import_polars() | | 361 | + warnings.simplefilter("ignore", bigframes.exceptions.PreviewWarning) | | 362 | + config.options.bigquery.enable_polars_execution = True | | 363 | + except ImportError: | | 364 | + pass # don't fail if polars isn't available | 366 | 365 |
| 367 | 366 | return global_session.with_default_session( | 368 | 367 | bigframes.session.Session._read_gbq_colab, | |
|