Skip to content

Commit

Permalink
Reset branch and added pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwoods2 committed Jan 21, 2024
1 parent 8ec8c32 commit 54031f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion package/MDAnalysis/coordinates/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ def __init__(self, filenames, skip=1, dt=None, continuous=False,
for filename in filenames]
self.filenames = np.array([fn[0] if isinstance(fn, tuple) else fn
for fn in filenames])
# Set filenames array to array of "None" if chainreader initialized with
# numpy arrays
if isinstance(filenames[0], np.ndarray):
self.filenames = np.array(["None" for _ in range(len(filenames))])
else:
self.filenames = np.array([fn[0] if isinstance(fn, tuple) else fn
for fn in filenames])
# pointer to "active" trajectory index into self.readers
self.__active_reader_index = 0

Expand Down Expand Up @@ -597,7 +604,9 @@ def close(self):
self._apply('close')

def __repr__(self):
if len(self.filenames) > 3:
if self.filenames[0] == "None":
fnames = "NumPy array"
elif len(self.filenames) > 3:
fnames = "{fname} and {nfanmes} more".format(
fname=os.path.basename(self.filenames[0]),
nfanmes=len(self.filenames) - 1)
Expand Down
6 changes: 6 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_chainreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,9 @@ def wrapped(ts):
# in the issue report values of ~25 were seen before the fix
# with the fix all values should be <1e-6
assert np.abs(com).max() < 1e-6

def test_issue_3349():
# test for repr of a chainreader when the subreaders are memoryreaders
cdx = np.random.random(3341*3*10).reshape(-1, 3341, 3).astype(np.float32) * 10
u = mda.Universe(PSF, (cdx, cdx))
assert(repr(u.trajectory) == "<ChainReader containing NumPy array with 20 frames of 3341 atoms>")

0 comments on commit 54031f0

Please sign in to comment.