4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 21
21
22
22
import google .api_core .exceptions
23
23
import google .auth .credentials
24
+ import jellyfish
24
25
25
26
import bigframes .constants
26
27
import bigframes .exceptions
30
31
"Call bigframes.pandas.close_session() first, if you are using the bigframes.pandas API."
31
32
)
32
33
33
- UNKNOWN_LOCATION_MESSAGE = "The location '{location}' is set to an unknown value."
34
+
35
+ UNKNOWN_LOCATION_MESSAGE = "The location '{location}' is set to an unknown value. Did you mean '{possibility}'?"
34
36
35
37
36
38
def _validate_location (value : Optional [str ]):
@@ -39,8 +41,13 @@ def _validate_location(value: Optional[str]):
39
41
return
40
42
41
43
if value not in bigframes .constants .ALL_BIGQUERY_LOCATIONS :
44
+ location = str (value )
45
+ possibility = min (
46
+ bigframes .constants .ALL_BIGQUERY_LOCATIONS ,
47
+ key = lambda item : jellyfish .levenshtein_distance (location , item ),
48
+ )
42
49
warnings .warn (
43
- UNKNOWN_LOCATION_MESSAGE .format (location = value ),
50
+ UNKNOWN_LOCATION_MESSAGE .format (location = location , possibility = possibility ),
44
51
# There are many layers before we get to (possibly) the user's code:
45
52
# -> bpd.options.bigquery.location = "us-central-1"
46
53
# -> location.setter
Original file line number Diff line number Diff line change 12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+
15
16
import io
16
17
import itertools
17
18
import os
45
46
"google-cloud-resource-manager >=1.10.3" ,
46
47
"google-cloud-storage >=2.0.0" ,
47
48
"ibis-framework[bigquery] >=8.0.0,<9.0.0dev" ,
49
+ "jellyfish >=0.8.9" ,
48
50
# TODO: Relax upper bound once we have fixed `system_prerelease` tests.
49
51
"pandas >=1.5.0" ,
50
52
"pyarrow >=8.0.0" ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ google-cloud-iam==2.12.1
11
11
google-cloud-resource-manager==1.10.3
12
12
google-cloud-storage==2.0.0
13
13
ibis-framework==8.0.0
14
+ jellyfish==0.8.9
14
15
pandas==1.5.0
15
16
pyarrow==8.0.0
16
17
pydata-google-auth==1.8.2
Original file line number Diff line number Diff line change @@ -108,24 +108,25 @@ def test_location_set_to_valid_no_warning(valid_location):
108
108
@pytest .mark .parametrize (
109
109
[
110
110
"invalid_location" ,
111
+ "possibility" ,
111
112
],
112
113
[
113
114
# Test with common mistakes, see article.
114
115
# https://en.wikipedia.org/wiki/Edit_distance#Formal_definition_and_properties
115
116
# Substitution
116
- ("us-wist-3" , ),
117
+ ("us-wist3" , "us-west3" ),
117
118
# Insertion
118
- ("us-central-1" ,),
119
+ ("us-central-1" , "us-central1" ),
119
120
# Deletion
120
- ("asia-suth2" ,),
121
+ ("asia-suth2" , "asia-south2" ),
121
122
],
122
123
)
123
- def test_location_set_to_invalid_warning (invalid_location ):
124
+ def test_location_set_to_invalid_warning (invalid_location , possibility ):
124
125
options = bigquery_options .BigQueryOptions ()
125
126
with pytest .warns (
126
127
bigframes .exceptions .UnknownLocationWarning ,
127
128
match = re .escape (
128
- f"The location '{ invalid_location } ' is set to an unknown value."
129
+ f"The location '{ invalid_location } ' is set to an unknown value. Did you mean ' { possibility } '? "
129
130
),
130
131
):
131
132
options .location = invalid_location
0 commit comments