Skip to content

Commit

Permalink
Merge pull request #266 from nlesc-nano/param
Browse files Browse the repository at this point in the history
BUG: Fix the param columns being incorrectly written to the .hdf5 file
  • Loading branch information
BvB93 committed Feb 3, 2022
2 parents 933242f + fa92490 commit bd416d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion FOX/io/hdf5_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def create_hdf5(filename: PathType, armc: ARMC) -> None:
pd_dict = {
'aux_error': pd.Series(np.nan, index=aux_error_idx, name='aux_error'),
'aux_error_mod': pd.Series(np.nan, index=idx, name='aux_error_mod'),
'param': armc.param.param[0],
'param': armc.param.param,
'phi': pd.Series(np.nan, index=np.arange(kappa), name='phi'),
}
pd_dict2 = {
Expand Down Expand Up @@ -811,6 +811,9 @@ def dset_to_df(f: File, key: str) -> Union[pd.DataFrame, List[pd.DataFrame]]:
else:
data = f[key][:]

if key == "/param":
data = np.swapaxes(data, 1, 2)

# Return a DataFrame or list of DataFrames
if data.ndim == 2:
return pd.DataFrame(data, index=index, columns=columns)
Expand Down
4 changes: 3 additions & 1 deletion FOX/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import re
import warnings
from types import MappingProxyType
from os import listdir
Expand Down Expand Up @@ -256,8 +257,9 @@ def load_results(workdir, *, result_type=CP2KMM_Result, n=1): # noqa: E302
ret = []
tmp = []
i = -n
file_pattern = re.compile(r"md(\.([0-9]+))?")
for jobname in sorted(listdir(workdir_path)):
if jobname == '__pycache__':
if file_pattern.fullmatch(jobname) is None:
continue

plams_dir = workdir_path / jobname
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hdf5_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,6 @@ def test_from_hdf5():
assertion.eq(hdf5_dict['aux_error'], out['aux_error']['rdf.0'][0])
assertion.eq(hdf5_dict['phi'], out['aux_error_mod'].values[:, -1])
assertion.eq(hdf5_dict['phi'][0], out['phi'].loc[0, 0])
np.testing.assert_allclose(hdf5_dict['param'], out['param'].values)
np.testing.assert_allclose(hdf5_dict['param'], out['param'][0].T)
np.testing.assert_allclose(hdf5_dict['rdf.0'], out['rdf.0'][0].values)
np.testing.assert_array_equal(PARAM_METADATA, out['param_metadata'])

0 comments on commit bd416d2

Please sign in to comment.