|
| 1 | +# Copyright 2023 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +def test_quickstart() -> None: |
| 17 | + import bigframes.pandas |
| 18 | + |
| 19 | + # We need a fresh session since we're modifying connection options. |
| 20 | + bigframes.pandas.close_session() |
| 21 | + |
| 22 | + # [START bigquery_bigframes_ordering_mode_partial] |
| 23 | + import bigframes.pandas as bpd |
| 24 | + |
| 25 | + bpd.options.bigquery.ordering_mode = "partial" |
| 26 | + # [END bigquery_bigframes_ordering_mode_partial] |
| 27 | + |
| 28 | + # [START bigquery_bigframes_ordering_mode_partial_ambiguous_window_warning] |
| 29 | + import warnings |
| 30 | + |
| 31 | + import bigframes.exceptions |
| 32 | + |
| 33 | + warnings.simplefilter( |
| 34 | + "ignore", category=bigframes.exceptions.AmbiguousWindowWarning |
| 35 | + ) |
| 36 | + # [END bigquery_bigframes_ordering_mode_partial_ambiguous_window_warning] |
| 37 | + |
| 38 | + df = bpd.DataFrame({"column": [1, 2, 1, 3, 1, 2, 3]}) |
| 39 | + |
| 40 | + # [START bigquery_bigframes_ordering_mode_partial_drop_duplicates] |
| 41 | + # Avoid order dependency by using groupby instead of drop_duplicates. |
| 42 | + unique_col = df.groupby(["column"], as_index=False).size().drop(columns="size") |
| 43 | + # [END bigquery_bigframes_ordering_mode_partial_drop_duplicates] |
| 44 | + |
| 45 | + assert len(unique_col) == 3 |
0 commit comments