Skip to content

Commit af6aa9c

Browse files
authored
chore: Add an ExperimentOptions class to control experiments (#1039)
1 parent 56fec28 commit af6aa9c

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

bigframes/_config/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import bigframes._config.bigquery_options as bigquery_options
3030
import bigframes._config.compute_options as compute_options
3131
import bigframes._config.display_options as display_options
32+
import bigframes._config.experiment_options as experiment_options
3233
import bigframes._config.sampling_options as sampling_options
3334

3435

@@ -46,6 +47,9 @@ class ThreadLocalConfig(threading.local):
4647
compute_options: compute_options.ComputeOptions = field(
4748
default_factory=compute_options.ComputeOptions
4849
)
50+
experiment_options: experiment_options.ExperimentOptions = field(
51+
default_factory=experiment_options.ExperimentOptions
52+
)
4953

5054

5155
class Options:
@@ -122,6 +126,16 @@ def compute(self) -> compute_options.ComputeOptions:
122126
"""
123127
return self._local.compute_options
124128

129+
@property
130+
def experiments(self) -> experiment_options.ExperimentOptions:
131+
"""Options controlling experiments
132+
133+
Returns:
134+
bigframes._config.experiment_options.ExperimentOptions:
135+
Thread-local options for controlling experiments
136+
"""
137+
return self._local.experiment_options
138+
125139
@property
126140
def is_bigquery_thread_local(self) -> bool:
127141
"""Indicator that we're using a thread-local session.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2024 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+
import warnings
16+
17+
18+
class ExperimentOptions:
19+
"""
20+
Encapsulates the configration for experiments
21+
"""
22+
23+
def __init__(self):
24+
self._semantic_operators = False
25+
26+
@property
27+
def semantic_operators(self) -> bool:
28+
return self._semantic_operators
29+
30+
@semantic_operators.setter
31+
def semantic_operators(self, value: bool):
32+
if value is True:
33+
warnings.warn(
34+
"Semantic operators are still under experiments, and are subject to change in the future."
35+
)
36+
self._semantic_operators = value
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2024 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+
import pytest
16+
17+
import bigframes._config.experiment_options as experiment_options
18+
19+
20+
def test_semantic_operators_default_false():
21+
options = experiment_options.ExperimentOptions()
22+
23+
assert options.semantic_operators is False
24+
25+
26+
def test_semantic_operators_set_true_shows_warning():
27+
options = experiment_options.ExperimentOptions()
28+
29+
with pytest.warns(UserWarning):
30+
options.semantic_operators = True
31+
32+
assert options.semantic_operators is True

0 commit comments

Comments
 (0)