File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 2121
2222import google .api_core .exceptions
2323import google .auth .credentials
24+ import jellyfish
2425
2526import bigframes .constants
2627import bigframes .exceptions
3031 "Call bigframes.pandas.close_session() first, if you are using the bigframes.pandas API."
3132)
3233
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}'?"
3436
3537
3638def _validate_location (value : Optional [str ]):
@@ -39,8 +41,13 @@ def _validate_location(value: Optional[str]):
3941 return
4042
4143 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+ )
4249 warnings .warn (
43- UNKNOWN_LOCATION_MESSAGE .format (location = value ),
50+ UNKNOWN_LOCATION_MESSAGE .format (location = location , possibility = possibility ),
4451 # There are many layers before we get to (possibly) the user's code:
4552 # -> bpd.options.bigquery.location = "us-central-1"
4653 # -> location.setter
Original file line number Diff line number Diff line change 1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+
1516import io
1617import itertools
1718import os
4546 "google-cloud-resource-manager >=1.10.3" ,
4647 "google-cloud-storage >=2.0.0" ,
4748 "ibis-framework[bigquery] >=8.0.0,<9.0.0dev" ,
49+ "jellyfish >=0.8.9" ,
4850 # TODO: Relax upper bound once we have fixed `system_prerelease` tests.
4951 "pandas >=1.5.0" ,
5052 "pyarrow >=8.0.0" ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ google-cloud-iam==2.12.1
1111google-cloud-resource-manager==1.10.3
1212google-cloud-storage==2.0.0
1313ibis-framework==8.0.0
14+ jellyfish==0.8.9
1415pandas==1.5.0
1516pyarrow==8.0.0
1617pydata-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):
108108@pytest .mark .parametrize (
109109 [
110110 "invalid_location" ,
111+ "possibility" ,
111112 ],
112113 [
113114 # Test with common mistakes, see article.
114115 # https://en.wikipedia.org/wiki/Edit_distance#Formal_definition_and_properties
115116 # Substitution
116- ("us-wist-3" , ),
117+ ("us-wist3" , "us-west3" ),
117118 # Insertion
118- ("us-central-1" ,),
119+ ("us-central-1" , "us-central1" ),
119120 # Deletion
120- ("asia-suth2" ,),
121+ ("asia-suth2" , "asia-south2" ),
121122 ],
122123)
123- def test_location_set_to_invalid_warning (invalid_location ):
124+ def test_location_set_to_invalid_warning (invalid_location , possibility ):
124125 options = bigquery_options .BigQueryOptions ()
125126 with pytest .warns (
126127 bigframes .exceptions .UnknownLocationWarning ,
127128 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 } '? "
129130 ),
130131 ):
131132 options .location = invalid_location
You can’t perform that action at this time.
0 commit comments