Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

BUG: Fix the param columns being incorrectly written to the .hdf5 file #266

Merged
merged 2 commits into from
Feb 3, 2022
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
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'])