diff --git a/CHANGELOG.md b/CHANGELOG.md index d3e4a991..cdd3f5e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pam/read/matsim.py b/pam/read/matsim.py index 52e19ad2..c424468d 100644 --- a/pam/read/matsim.py +++ b/pam/read/matsim.py @@ -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: diff --git a/tests/test_03_read_matsim.py b/tests/test_03_read_matsim.py index 17198fe7..cee8a7bc 100644 --- a/tests/test_03_read_matsim.py +++ b/tests/test_03_read_matsim.py @@ -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(): + text = """ + + 10.0 + + """ + elem = et.fromstring(text) + pid, attributes = get_attributes_from_person(elem) + assert isinstance(attributes["age"], float)