-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support for new data types when reading/writing networks #73
Conversation
# Conflicts: # tests/test_core_schedule_elements.py # tests/test_outputs_handler_geojson.py
# Conflicts: # tests/test_core_schedule_elements.py # tests/test_outputs_handler_geojson.py
# Conflicts: # tests/test_core_network.py # tests/test_outputs_handler_geojson.py # tests/test_use_schedule.py
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.
Looks good.
I've made a comment or two in the tests asking if there are any ways we could be clearer about why we have some of the expectations we're asserting against, which is a question that applied to a fair number of different tests.
I also noticed we have an XFAIL test (tests/test_core_schedule_elements.py::test_splitting_service_edge_case_on_direction_results_in_two_directions XFAIL
) and a lot of warnings:
669 passed, 1 xfailed, 440 warnings in 550.78s (0:09:10)
Might be worth cleaning those up in a separate story.
stop_times_db[row['trip_id']].append(dict(row)) | ||
else: | ||
stop_times_db[row['trip_id']] = [dict(row)] | ||
stop_times_db = pd.read_csv(file, dtype={'trip_id': str, 'stop_id': str}, low_memory=False) |
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.
I like this more flexible approach. A lot less code duplication.
json_data = json.load(json_file) | ||
for node, data in json_data['nodes'].items(): | ||
try: | ||
del data['geometry'] |
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.
How often would we expect the geometry key/value pair to be missing? Is it normally there, normally missing, or 50/50?
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.
Depending on where this json comes from, all of the geometry might be missing (it's not a requirement for a json network format) or none of it will be missing (genet exports node geometry to json, so if you read it back, it'll all be there)
genet/outputs_handler/csv.py
Outdated
expected schema | ||
:return: genet.Network object | ||
""" | ||
pass |
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.
Is this supposed to be an empty implementation?
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.
lol, I put a placeholder there and then ended up putting the method somewhere else 😂
@@ -208,7 +217,7 @@ | |||
], | |||
"metadata": { | |||
"kernelspec": { | |||
"display_name": "Python (genet)", | |||
"display_name": "genet", | |||
"language": "python", | |||
"name": "genet" |
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.
That reminds me - the notebook smoke test should be discovering all of the kernel names dynamically by reading the notebooks themselves. At the moment, you have to pass the name manually. I'll nice up the smoke test soon to make it more like the one in PAM.
@@ -222,7 +231,7 @@ | |||
"name": "python", | |||
"nbconvert_exporter": "python", | |||
"pygments_lexer": "ipython3", | |||
"version": "3.8.6" | |||
"version": "3.7.0" |
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.
Is this a deliberate version downgrade?
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.
probably not deliberate, I had to make a new virtual environment for genet at one point. I think this is better (genet's requirement is >=3.7 so I should probably use the lowest version ?)
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.
I don't think it really matters which version you use, so long as you're deliberate and consistent.
tests/test_core_network.py
Outdated
|
||
|
||
def test_transforming_network_to_json(network1, json_network): | ||
assert_semantically_equal(network1.to_json(), json_network) |
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.
You could maybe return the network and its expected JSON representation from the same fixture, so that the fixture gives you the data and the expectation. So this test would look something like:
def test_transforming_network_to_json(network):
assert_semantically_equal(network['network'].to_json(), network['expected_json'])
Tying the network and it's representation as a dictionary together makes it clearer why we expect what we're asserting on, I think.
tests/test_core_network.py
Outdated
|
||
def test_saving_network_to_json(network1, json_network, tmpdir): | ||
network1.apply_attributes_to_links( | ||
{'0': { |
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.
Why do we add the linestring to this node? It feels like this might be a test in its own right (when you add an attribute, do you see it persisted, I mean).
tests/test_core_network.py
Outdated
json_network['links']['0']['modes'] = 'car' | ||
assert_semantically_equal( | ||
output_json, | ||
{'nodes': { |
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.
Is there a way to be clearer about why we expect the things we're asserting on? Would the pattern of tying the fixture data to its expected value make this clearer? If not, is there another way?
Adds support (read/write) for:
network.write_to_geojson(path)
Adds nice class methods for both
Network
andSchedule
objects to put them in the formats mentioned aboveto_json
to_geodataframe
Changes MATSim read methods - breaking change. All read methods are now stored in the read module, which can be imported in the following way, e.g
where you have a selection of read methods, all return a genet object from that data type. The syntax to read a MATSim network changes from:
to
OSM reading method also moved to the
read
module for consistence.Adds a lot of new test/example data and jupyter notebooks which which show examples and talk about the schema if you want to read data and limitations of what gets saved if you're saving it out.