From 66b884afe012dbd66a9409a3fe00c4dbcc3ceced Mon Sep 17 00:00:00 2001 From: "Theodore.Chatziioannou" Date: Mon, 30 Oct 2023 16:43:31 +0000 Subject: [PATCH 1/2] fix bug --- CHANGELOG.md | 1 + pam/read/matsim.py | 2 +- tests/test_03_read_matsim.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) 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..99d9516c 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) From f8d10df20e7a559382890ff324ce196aa3aaca7d Mon Sep 17 00:00:00 2001 From: "Theodore.Chatziioannou" Date: Mon, 30 Oct 2023 17:08:27 +0000 Subject: [PATCH 2/2] pre-commit --- tests/test_03_read_matsim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_03_read_matsim.py b/tests/test_03_read_matsim.py index 99d9516c..cee8a7bc 100644 --- a/tests/test_03_read_matsim.py +++ b/tests/test_03_read_matsim.py @@ -220,4 +220,4 @@ def test_get_float_attribute_from_person(): """ elem = et.fromstring(text) pid, attributes = get_attributes_from_person(elem) - assert isinstance(attributes['age'], float) + assert isinstance(attributes["age"], float)