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 bug #264

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- **internal** conda upload CI script.
- **public** fix person attributes type conversion bug ([#263](https://github.com/arup-group/pam/issues/263))

### Added

Expand Down
2 changes: 1 addition & 1 deletion pam/read/matsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def get_attributes_from_person(elem):
elif attribute_type == "java.lang.Integer":
attributes[attribute_name] = int(attr.text)
elif attribute_type == "java.lang.Double":
attributes[attribute_name] = float(attr)
attributes[attribute_name] = float(attr.text)
elif attribute_type == "org.matsim.vehicles.PersonVehicles":
attributes[attribute_name] = parse_veh_attribute(attr.text)
# last try:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_03_read_matsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,14 @@ def test_get_attributes_from_person():
assert pid == "chris"
assert attributes["hid"] == "A"
assert attributes["vehicles"] == {"car": "chris"}


def test_get_float_attribute_from_person():
Copy link
Contributor

Choose a reason for hiding this comment

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

When you ran this test before fixing the bug, did it throw an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was trying to cast a lxml element as float (float(attr)), instead of the element value (attr.text)

text = """<person id="chris">
<attributes>
<attribute name="age" class="java.lang.Double">10.0</attribute>
</attributes>
</person>"""
elem = et.fromstring(text)
pid, attributes = get_attributes_from_person(elem)
assert isinstance(attributes["age"], float)