|
16 | 16 | def test_quickstart() -> None:
|
17 | 17 | import bigframes.pandas
|
18 | 18 |
|
19 |
| - # We need a fresh session since we're modifying connection options. |
20 |
| - bigframes.pandas.close_session() |
| 19 | + try: |
| 20 | + # We need a fresh session since we're modifying connection options. |
| 21 | + bigframes.pandas.close_session() |
21 | 22 |
|
22 |
| - # [START bigquery_bigframes_ordering_mode_partial] |
23 |
| - import bigframes.pandas as bpd |
| 23 | + # [START bigquery_bigframes_ordering_mode_partial] |
| 24 | + import bigframes.pandas as bpd |
24 | 25 |
|
25 |
| - bpd.options.bigquery.ordering_mode = "partial" |
26 |
| - # [END bigquery_bigframes_ordering_mode_partial] |
| 26 | + bpd.options.bigquery.ordering_mode = "partial" |
| 27 | + # [END bigquery_bigframes_ordering_mode_partial] |
27 | 28 |
|
28 |
| - # [START bigquery_bigframes_ordering_mode_partial_ambiguous_window_warning] |
29 |
| - import warnings |
| 29 | + # [START bigquery_bigframes_ordering_mode_partial_ambiguous_window_warning] |
| 30 | + import warnings |
30 | 31 |
|
31 |
| - import bigframes.exceptions |
| 32 | + import bigframes.exceptions |
32 | 33 |
|
33 |
| - warnings.simplefilter( |
34 |
| - "ignore", category=bigframes.exceptions.AmbiguousWindowWarning |
35 |
| - ) |
36 |
| - # [END bigquery_bigframes_ordering_mode_partial_ambiguous_window_warning] |
| 34 | + warnings.simplefilter( |
| 35 | + "ignore", category=bigframes.exceptions.AmbiguousWindowWarning |
| 36 | + ) |
| 37 | + # [END bigquery_bigframes_ordering_mode_partial_ambiguous_window_warning] |
37 | 38 |
|
38 |
| - df = bpd.DataFrame({"column": [1, 2, 1, 3, 1, 2, 3]}) |
| 39 | + df = bpd.DataFrame({"column": [1, 2, 1, 3, 1, 2, 3]}) |
39 | 40 |
|
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] |
| 41 | + # [START bigquery_bigframes_ordering_mode_partial_drop_duplicates] |
| 42 | + # Avoid order dependency by using groupby instead of drop_duplicates. |
| 43 | + unique_col = df.groupby(["column"], as_index=False).size().drop(columns="size") |
| 44 | + # [END bigquery_bigframes_ordering_mode_partial_drop_duplicates] |
44 | 45 |
|
45 |
| - assert len(unique_col) == 3 |
| 46 | + assert len(unique_col) == 3 |
| 47 | + finally: |
| 48 | + # Don't leak partial ordering mode to other code samples. |
| 49 | + bigframes.pandas.close_session() |
| 50 | + bpd.options.bigquery.ordering_mode = "strict" |
0 commit comments