Skip to content

Commit

Permalink
Merge pull request #22 from ezavod/fix/old-file-versions
Browse files Browse the repository at this point in the history
Fix/old file versions
  • Loading branch information
jbarnoud authored Oct 29, 2023
2 parents 29a2cef + fa7f8b5 commit 1b1b3c4
Show file tree
Hide file tree
Showing 42 changed files with 1,298 additions and 130 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ The rules for this file:
* Note: rules were not applied before v0.6.0

------------------------------------------------------------------------------
??/??/???? ezavod

* 0.8.0

Changes

* Added support for legacy file version 1 (PR #22)
* Extended test coverage and code cleanup (PR #22)

09/04/2023 IAlibay

* 0.7.2
Expand Down
6 changes: 5 additions & 1 deletion panedr/panedr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
from .panedr import edr_to_df, get_unit_dictionary
import pbr.version
from .panedr import ENX_VERSION, edr_to_df, get_unit_dictionary
__version__ = pbr.version.VersionInfo('panedr').release_string()
del pbr

# export `ENX_VERSION` for version checking in tests
# this is not useful for normal use
__all__ = ['ENX_VERSION', 'edr_to_df', 'get_unit_dictionary']
6 changes: 3 additions & 3 deletions panedr/panedr/panedr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#-*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
# Panedr -- a library to manipulate Gromacs EDR file in python
# Copyright (C) 2016 Jonathan Barnoud
#
Expand Down Expand Up @@ -37,11 +37,11 @@
.. autofunction:: edr_to_df
"""

from pyedr import read_edr, get_unit_dictionary
import pandas as pd
from pyedr import ENX_VERSION, read_edr, get_unit_dictionary


__all__ = ['edr_to_df', 'get_unit_dictionary']
__all__ = ['ENX_VERSION', 'edr_to_df', 'get_unit_dictionary']


def edr_to_df(path: str, verbose: bool = False) -> pd.DataFrame:
Expand Down
44 changes: 24 additions & 20 deletions panedr/panedr/tests/test_edr.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

"""
Tests for panedr
"""

import sys
import pytest
import contextlib
import re
from io import StringIO
from collections import namedtuple
from pathlib import Path
import pickle

import numpy as np
from numpy.testing import assert_allclose
import pandas
import pyedr
from pyedr.tests.test_edr import read_xvg, redirect_stderr
from pyedr.tests.datafiles import (
EDR, EDR_XVG, EDR_UNITS, EDR_IRREG, EDR_IRREG_XVG,
EDR_IRREG_UNITS, EDR_DOUBLE, EDR_DOUBLE_XVG, EDR_DOUBLE_UNITS,
EDR_BLOCKS, EDR_BLOCKS_XVG, EDR_BLOCKS_UNITS
)
from pyedr.tests.datafiles import EDR, EDR_XVG, TESTFILE_PARAMS

import panedr

Expand All @@ -39,18 +32,28 @@
'xvgfile'])


def check_version_warning(func, edrfile, version):
if version == panedr.ENX_VERSION:
return func(edrfile)
else:
with pytest.warns(
UserWarning,
match=f'enx file_version {version}, '
f'implementation version {panedr.ENX_VERSION}'
):
return func(edrfile)


@pytest.fixture(scope='module',
params=[(EDR, EDR_XVG, EDR_UNITS),
(EDR_IRREG, EDR_IRREG_XVG, EDR_IRREG_UNITS),
(EDR_DOUBLE, EDR_DOUBLE_XVG, EDR_DOUBLE_UNITS),
(EDR_BLOCKS, EDR_BLOCKS_XVG, EDR_BLOCKS_UNITS),
(Path(EDR), EDR_XVG, EDR_UNITS), ])
params=TESTFILE_PARAMS)
def edr(request):
edrfile, xvgfile, unitfile = request.param
df = panedr.edr_to_df(edrfile)
df_units = panedr.get_unit_dictionary(edrfile)
edr_dict = pyedr.edr_to_dict(edrfile)
edr_units = pyedr.get_unit_dictionary(edrfile)
edrfile, xvgfile, unitfile, version = request.param
df = check_version_warning(panedr.edr_to_df, edrfile, version)
df_units = check_version_warning(panedr.get_unit_dictionary,
edrfile, version)
edr_dict = check_version_warning(pyedr.edr_to_dict, edrfile, version)
edr_units = check_version_warning(pyedr.get_unit_dictionary,
edrfile, version)
with open(unitfile, "rb") as f:
true_units = pickle.load(f)
xvgdata, xvgnames, xvgprec = read_xvg(xvgfile)
Expand Down Expand Up @@ -81,7 +84,8 @@ def test_columns(self, edr):
"""
columns = edr.df.columns.values
if columns.shape[0] == edr.xvgcols.shape[0]:
print('These columns differ from the reference (displayed as read):')
print('These columns differ from the reference '
'(displayed as read):')
print(columns[edr.xvgcols != columns])
print('The corresponding names displayed as reference:')
print(edr.xvgcols[edr.xvgcols != columns])
Expand Down
2 changes: 1 addition & 1 deletion panedr/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
setup_requires=['pbr'],
pbr=True,
include_package_data=True,
)
)
6 changes: 5 additions & 1 deletion pyedr/pyedr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
from .pyedr import edr_to_dict, read_edr, get_unit_dictionary
from .pyedr import ENX_VERSION, edr_to_dict, read_edr, get_unit_dictionary
import pbr.version
__version__ = pbr.version.VersionInfo('pyedr').release_string()
del pbr

# export `ENX_VERSION` for version checking in tests
# this is not useful for normal use
__all__ = ['ENX_VERSION', 'edr_to_dict', 'read_edr', 'get_unit_dictionary']
Loading

0 comments on commit 1b1b3c4

Please sign in to comment.