Skip to content

Commit

Permalink
Fixed small bug on data_read with no attached attributes. Removed att…
Browse files Browse the repository at this point in the history
…ributes from dedicated test.

Signed-off-by: javier.hernandez <javier.hernandez@meaningfuldata.eu>
  • Loading branch information
javihern98 committed Jul 8, 2024
1 parent e8ba36d commit 4d30a78
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
15 changes: 6 additions & 9 deletions src/pysdmx/io/xml/sdmx21/reader/data_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def __reading_generic_series(dataset: Dict[str, Any]) -> pd.DataFrame:

for data in series[OBS]:
obs = {OBS_DIM: data[OBS_DIM][VALUE.lower()],
OBSVALUE.upper(): None}
if OBSVALUE in data:
obs[OBSVALUE.upper()] = data[OBSVALUE][VALUE.lower()]
OBSVALUE.upper(): data[OBSVALUE][VALUE.lower()]}
if ATTRIBUTES in data:
obs = {**obs, **__get_element_to_list(data, mode=ATTRIBUTES)}
test_list.append({**keys, **obs})
Expand All @@ -124,11 +122,8 @@ def __reading_generic_all(dataset: Dict[str, Any]) -> pd.DataFrame:
dataset[OBS] = add_list(dataset[OBS])
for data in dataset[OBS]:
obs: Dict[str, Any] = {}
obs = {**obs, **__get_element_to_list(data, mode=OBSKEY)}
if ID in data[OBSVALUE]:
obs[data[OBSVALUE][ID]] = data[OBSVALUE][VALUE.lower()]
else:
obs[OBSVALUE.upper()] = data[OBSVALUE][VALUE.lower()]
obs = {**obs, **__get_element_to_list(data, mode=OBSKEY),
OBSVALUE.upper(): data[OBSVALUE][VALUE.lower()]}
if ATTRIBUTES in data:
obs = {**obs, **__get_element_to_list(data, mode=ATTRIBUTES)}
test_list.append({**obs})
Expand Down Expand Up @@ -182,7 +177,9 @@ def __get_at_att_str(dataset: Dict[str, Any]) -> Dict[str, Any]:

def __get_at_att_gen(dataset: Dict[str, Any]) -> Dict[str, Any]:
"""Gets all the elements if it is Generic data."""
attached_attributes = {}
attached_attributes: Dict[str, Any] = {}
if ATTRIBUTES not in dataset:
return attached_attributes
dataset[ATTRIBUTES][VALUE] = add_list(dataset[ATTRIBUTES][VALUE])
for k in dataset[ATTRIBUTES][VALUE]:
attached_attributes[k[ID]] = k[VALUE.lower()]
Expand Down
6 changes: 0 additions & 6 deletions tests/io/xml/sdmx21/reader/samples/gen_all_no_atts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
<generic:Value id="TIME_PERIOD" value="2002"/>
</generic:ObsKey>
<generic:ObsValue value=""/>
<generic:Attributes>
<generic:Value id="AVAILABILITY" value="K"/>
<generic:Value id="COLLECTION" value="S"/>
<generic:Value id="OBS_STATUS" value="M"/>
<generic:Value id="OBS_CONF" value="F"/>
</generic:Attributes>
</generic:Obs>
</message:DataSet>
</message:GenericData>
6 changes: 2 additions & 4 deletions tests/io/xml/sdmx21/reader/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,11 @@ def test_gen_all_no_atts(samples_folder):
data_path = samples_folder / "gen_all_no_atts.xml"
input_str, filetype = process_string_to_read(data_path)
assert filetype == "xml"
with pytest.raises(KeyError, match="Attributes"):
read_xml(input_str, validate=True)
read_xml(input_str, validate=True)


def test_gen_ser_no_atts(samples_folder):
data_path = samples_folder / "gen_ser_no_atts.xml"
input_str, filetype = process_string_to_read(data_path)
assert filetype == "xml"
with pytest.raises(KeyError, match="Attributes"):
read_xml(input_str, validate=True)
read_xml(input_str, validate=True)

0 comments on commit 4d30a78

Please sign in to comment.