-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow kwargs in network creation to override Class-level variables for Roadway and Transit #312
Conversation
…roadway network. Also: - added util method: class_vars() - test network links which use different Key than model_link_id Tested via: test_kwarg_instantiation()
} | ||
|
||
net = RoadwayNetwork.read( | ||
link_file=SMALL_LINK_FILE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be testing with the link_diffIDs.json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test fails when using the link_diffIDs.json. Error:
2023-07-06 15:20:19, ERROR: Network doesn't contain unique link identifier: model_link_id
@@ -163,17 +163,17 @@ class RoadwayNetwork(object): | |||
|
|||
UNIQUE_LINK_KEY = "model_link_id" | |||
UNIQUE_NODE_KEY = "model_node_id" | |||
UNIQUE_MODEL_LINK_IDENTIFIERS = ["model_link_id"] | |||
UNIQUE_MODEL_LINK_IDENTIFIERS = [UNIQUE_LINK_KEY] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the example test test_kwarg_instantiation()
in test_roadway.py, we update the UNIQUE_LINK_KEY
to "different_link_id"
, which works, but it does not automatically update the reference of UNIQUE_LINK_KEY
in the class, i.e., the UNIQUE_MODEL_LINK_IDENTIFIEDS
here would still be ["model_link_id"]
, which is causing the test using "links_DiffIDs.json" to fail.
We need to refresh all class attrs whenever setattr() is called.
WranglerLogger.warning(f"{k} specified in TransitNetwork kwargs but does not match a Class-level variable.") | ||
continue | ||
WranglerLogger.debug(f"Updating TransityNetwork.{k.upper()} to: {v}") | ||
setattr(RoadwayNetwork,k.upper(),v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here for the same issue in roadwaynetwork.py
WranglerLogger.warning(f"{k} specified in RoadwayNetwork kwargs but does not match a Class-level variable.") | ||
continue | ||
WranglerLogger.debug(f"Updating RoadwayNetwork.{k.upper()} to: {v}") | ||
setattr(RoadwayNetwork,k.upper(),v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after this setattr(), can we refresh all the attrs?
Closing this as this approach has been superceeded by aligning on a string model for IDs across all tables in the |
This PR adds steps to the
read()
function for both RoadwayNetwork and TransitNetwork which will read in kwargs from theread()
variables and will update any matching (upper-case) class-level variables to the specified values.This is useful for when an agency might need to use a different unique ID or variable set from the defaults.
Also:
class_vars()
model_link_id
Tested via:
test_kwarg_instantiation()
Closes Issue #290