|
21 | 21 | import functools |
22 | 22 | import operator |
23 | 23 | import typing |
24 | | -from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union, Sequence |
25 | | - |
26 | 24 | import warnings |
| 25 | +from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Tuple, Union |
27 | 26 |
|
28 | 27 | try: |
29 | 28 | import pandas # type: ignore |
|
56 | 55 | _read_wkt = wkt.loads |
57 | 56 |
|
58 | 57 | import google.api_core.exceptions |
59 | | -from google.api_core.page_iterator import HTTPIterator |
60 | | - |
61 | 58 | import google.cloud._helpers # type: ignore |
62 | | -from google.cloud.bigquery import _helpers |
63 | | -from google.cloud.bigquery import _pandas_helpers |
64 | | -from google.cloud.bigquery import _versions_helpers |
| 59 | +from google.api_core.page_iterator import HTTPIterator |
| 60 | +from google.cloud.bigquery import ( |
| 61 | + _helpers, |
| 62 | + _pandas_helpers, |
| 63 | + _string_references, |
| 64 | + _versions_helpers, |
| 65 | + external_config, |
| 66 | +) |
65 | 67 | from google.cloud.bigquery import exceptions as bq_exceptions |
| 68 | +from google.cloud.bigquery import schema as _schema |
66 | 69 | from google.cloud.bigquery._tqdm_helpers import get_progress_bar |
67 | 70 | from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration |
68 | 71 | from google.cloud.bigquery.enums import DefaultPandasDTypes |
69 | 72 | from google.cloud.bigquery.external_config import ExternalConfig |
70 | | -from google.cloud.bigquery import schema as _schema |
71 | | -from google.cloud.bigquery.schema import _build_schema_resource |
72 | | -from google.cloud.bigquery.schema import _parse_schema_resource |
73 | | -from google.cloud.bigquery.schema import _to_schema_fields |
74 | | -from google.cloud.bigquery import external_config |
75 | | -from google.cloud.bigquery import _string_references |
| 73 | +from google.cloud.bigquery.schema import ( |
| 74 | + _build_schema_resource, |
| 75 | + _parse_schema_resource, |
| 76 | + _to_schema_fields, |
| 77 | +) |
76 | 78 |
|
77 | 79 | if typing.TYPE_CHECKING: # pragma: NO COVER |
78 | 80 | # Unconditionally import optional dependencies again to tell pytype that |
79 | 81 | # they are not None, avoiding false "no attribute" errors. |
| 82 | + import geopandas # type: ignore |
80 | 83 | import pandas |
81 | 84 | import pyarrow |
82 | | - import geopandas # type: ignore |
83 | 85 | from google.cloud import bigquery_storage # type: ignore |
84 | 86 | from google.cloud.bigquery.dataset import DatasetReference |
85 | 87 |
|
|
110 | 112 | "pyarrow >= 10.0.1." |
111 | 113 | ) |
112 | 114 |
|
| 115 | +_TO_DATAFRAME_DEPRECATED = ( |
| 116 | + "Retrieving DataFrames via google-cloud-bigquery is deprecated. " |
| 117 | + "For direct, optimized access, please call 'pandas_gbq.read_gbq()' directly." |
| 118 | +) |
| 119 | + |
| 120 | +_TO_ARROW_DEPRECATED = ( |
| 121 | + "Retrieving PyArrow Tables via google-cloud-bigquery is deprecated. " |
| 122 | + "For direct, optimized access, please call 'pandas_gbq.arrow.read_bigquery_table()' " |
| 123 | + "or 'pandas_gbq.arrow.read_bigquery_query()' directly." |
| 124 | +) |
| 125 | + |
113 | 126 | # How many of the total rows need to be downloaded already for us to skip |
114 | 127 | # calling the BQ Storage API? |
115 | 128 | # |
@@ -2316,6 +2329,12 @@ def to_arrow( |
2316 | 2329 |
|
2317 | 2330 | .. versionadded:: 1.17.0 |
2318 | 2331 | """ |
| 2332 | + warnings.warn( |
| 2333 | + _TO_ARROW_DEPRECATED, |
| 2334 | + PendingDeprecationWarning, |
| 2335 | + stacklevel=2, |
| 2336 | + ) |
| 2337 | + |
2319 | 2338 | if pyarrow is None: |
2320 | 2339 | raise ValueError(_NO_PYARROW_ERROR) |
2321 | 2340 |
|
@@ -2709,6 +2728,12 @@ def to_dataframe( |
2709 | 2728 | is not supported dtype. |
2710 | 2729 |
|
2711 | 2730 | """ |
| 2731 | + warnings.warn( |
| 2732 | + _TO_DATAFRAME_DEPRECATED, |
| 2733 | + PendingDeprecationWarning, |
| 2734 | + stacklevel=2, |
| 2735 | + ) |
| 2736 | + |
2712 | 2737 | _pandas_helpers.verify_pandas_imports() |
2713 | 2738 |
|
2714 | 2739 | if geography_as_object and shapely is None: |
@@ -2801,12 +2826,18 @@ def to_dataframe( |
2801 | 2826 | create_bqstorage_client = False |
2802 | 2827 | bqstorage_client = None |
2803 | 2828 |
|
2804 | | - record_batch = self.to_arrow( |
2805 | | - progress_bar_type=progress_bar_type, |
2806 | | - bqstorage_client=bqstorage_client, |
2807 | | - create_bqstorage_client=create_bqstorage_client, |
2808 | | - timeout=timeout, |
2809 | | - ) |
| 2829 | + with warnings.catch_warnings(): |
| 2830 | + warnings.filterwarnings( |
| 2831 | + "ignore", |
| 2832 | + category=PendingDeprecationWarning, |
| 2833 | + message="Retrieving PyArrow Tables.*", |
| 2834 | + ) |
| 2835 | + record_batch = self.to_arrow( |
| 2836 | + progress_bar_type=progress_bar_type, |
| 2837 | + bqstorage_client=bqstorage_client, |
| 2838 | + create_bqstorage_client=create_bqstorage_client, |
| 2839 | + timeout=timeout, |
| 2840 | + ) |
2810 | 2841 |
|
2811 | 2842 | # Default date dtype is `db_dtypes.DateDtype()` that could cause out of bounds error, |
2812 | 2843 | # when pyarrow converts date values to nanosecond precision. To avoid the error, we |
@@ -3009,18 +3040,24 @@ def to_geodataframe( |
3009 | 3040 | "one to use to create a GeoDataFrame" |
3010 | 3041 | ) |
3011 | 3042 |
|
3012 | | - df = self.to_dataframe( |
3013 | | - bqstorage_client, |
3014 | | - dtypes, |
3015 | | - progress_bar_type, |
3016 | | - create_bqstorage_client, |
3017 | | - geography_as_object=True, |
3018 | | - bool_dtype=bool_dtype, |
3019 | | - int_dtype=int_dtype, |
3020 | | - float_dtype=float_dtype, |
3021 | | - string_dtype=string_dtype, |
3022 | | - timeout=timeout, |
3023 | | - ) |
| 3043 | + with warnings.catch_warnings(): |
| 3044 | + warnings.filterwarnings( |
| 3045 | + "ignore", |
| 3046 | + category=PendingDeprecationWarning, |
| 3047 | + message="Retrieving DataFrames via google-cloud-bigquery is deprecated.*", |
| 3048 | + ) |
| 3049 | + df = self.to_dataframe( |
| 3050 | + bqstorage_client, |
| 3051 | + dtypes, |
| 3052 | + progress_bar_type, |
| 3053 | + create_bqstorage_client, |
| 3054 | + geography_as_object=True, |
| 3055 | + bool_dtype=bool_dtype, |
| 3056 | + int_dtype=int_dtype, |
| 3057 | + float_dtype=float_dtype, |
| 3058 | + string_dtype=string_dtype, |
| 3059 | + timeout=timeout, |
| 3060 | + ) |
3024 | 3061 |
|
3025 | 3062 | return geopandas.GeoDataFrame( |
3026 | 3063 | df, crs=_COORDINATE_REFERENCE_SYSTEM, geometry=geography_column |
@@ -3068,6 +3105,11 @@ def to_arrow( |
3068 | 3105 | """ |
3069 | 3106 | if pyarrow is None: |
3070 | 3107 | raise ValueError(_NO_PYARROW_ERROR) |
| 3108 | + warnings.warn( |
| 3109 | + _TO_ARROW_DEPRECATED, |
| 3110 | + PendingDeprecationWarning, |
| 3111 | + stacklevel=2, |
| 3112 | + ) |
3071 | 3113 | return pyarrow.Table.from_arrays(()) |
3072 | 3114 |
|
3073 | 3115 | def to_dataframe( |
@@ -3114,6 +3156,11 @@ def to_dataframe( |
3114 | 3156 | Returns: |
3115 | 3157 | pandas.DataFrame: An empty :class:`~pandas.DataFrame`. |
3116 | 3158 | """ |
| 3159 | + warnings.warn( |
| 3160 | + _TO_DATAFRAME_DEPRECATED, |
| 3161 | + PendingDeprecationWarning, |
| 3162 | + stacklevel=2, |
| 3163 | + ) |
3117 | 3164 | _pandas_helpers.verify_pandas_imports() |
3118 | 3165 | return pandas.DataFrame() |
3119 | 3166 |
|
|
0 commit comments