Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiple avoid problem #417

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

shaiguelman
Copy link

Fixes #382

Modified distance_matrix so that the parameter "avoid" accepts multiple values, such as "tolls|highways".

@google-cla
Copy link

google-cla bot commented Sep 6, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no This human has *not* signed the Contributor License Agreement. label Sep 6, 2021
@shaiguelman
Copy link
Author

I have now signed the CLA, so that tag can be removed.

@google-cla google-cla bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Nov 4, 2021
@shaiguelman shaiguelman changed the title Fix multiple avoid problem Fix: multiple avoid problem Jan 29, 2022
@shaiguelman shaiguelman changed the title Fix: multiple avoid problem fix: multiple avoid problem Apr 10, 2022
@kostyafarber
Copy link

@shaiguelman do you need to add another label describing the pr to have it merged?

Copy link
Member

@wangela wangela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for offering this fix and for your patience. Let me know if you're willing to make these changes, or if you'd prefer me to submit a patch to your fork.

Please also add this parameter to the distance matrix test, which you can model off the test of the multi-argument parameter in test_directions.py

@@ -51,7 +51,8 @@ def distance_matrix(client, origins, destinations,
:type language: string

:param avoid: Indicates that the calculated route(s) should avoid the
indicated features. Valid values are "tolls", "highways" or "ferries".
indicated features. Valid values are "tolls", "highways" or "ferries"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "indoor"

@@ -51,7 +51,8 @@ def distance_matrix(client, origins, destinations,
:type language: string

:param avoid: Indicates that the calculated route(s) should avoid the
indicated features. Valid values are "tolls", "highways" or "ferries".
indicated features. Valid values are "tolls", "highways" or "ferries"
as well as any combination of them separated by "|".
:type avoid: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To mirror the implementation in directions.py, let's update this to list or string

@@ -107,8 +108,12 @@ def distance_matrix(client, origins, destinations,
params["language"] = language

if avoid:
if avoid not in ["tolls", "highways", "ferries"]:
raise ValueError("Invalid route restriction.")
valid_avoids = ["tolls", "highways", "ferries"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "indoor"

for token in avoid_tokens:
if token not in valid_avoids:
raise ValueError("Invalid route restriction.")
valid_avoids.remove(token)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean to remove from avoid_tokens

googlemaps/distance_matrix.py Show resolved Hide resolved
for token in avoid_tokens:
if token not in valid_avoids:
raise ValueError("Invalid route restriction.")
valid_avoids.remove(token)
params["avoid"] = avoid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to set it to the value of avoid_tokens right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where we could do parallel implementation with directions.py.
How about:

params["avoid"] = convert.join_list("|", avoid_tokens)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple avoid problems
3 participants