Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add deprecation warning for memoryreader inclusive indexing in timeseries. #3894

Merged
merged 11 commits into from
Nov 1, 2022
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Changes
* adding element attribute to TXYZParser if all atom names are valid element symbols (PR #3826)

Deprecations
* Add deprecation warning for inclusive stop indexing in
MemoryReader.timeseries (#PR 3894)


08/29/22 IAlibay, PicoCentauri, orbeckst, hmacdope, rmeli, miss77jun, rzhao271,
Expand Down
12 changes: 11 additions & 1 deletion package/MDAnalysis/coordinates/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,14 @@ def timeseries(self, asel=None, start=0, stop=-1, step=1, order='afc'):
of the underlying numpy array is returned, while a copy of the
data is returned whenever `asel` is different from ``None``.
start : int (optional)
the start trajectory frame
stop : int (optional)
the end trajectory frame
.. deprecated:: 2.4.0
Note that `stop` is currently *inclusive* but will be
changed in favour of being *exclusive* in version 3.0.
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
step : int (optional)
range of trajectory to access, `start` and `stop` are *inclusive*
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
the number of trajectory frames to skip
order : {"afc", "acf", "caf", "fac", "fca", "cfa"} (optional)
the order/shape of the return data array, corresponding
to (a)tom, (f)rame, (c)oordinates all six combinations
Expand All @@ -515,6 +520,11 @@ def timeseries(self, asel=None, start=0, stop=-1, step=1, order='afc'):
.. versionchanged:: 1.0.0
Deprecated `format` keyword has been removed. Use `order` instead.
"""
if stop != -1:
warnings.warn("MemoryReader.timeseries inclusive `stop` "
"indexing will be removed in 3.0 in favour of exclusive "
"indexing",category=DeprecationWarning)
orbeckst marked this conversation as resolved.
Show resolved Hide resolved

array = self.get_array()
if order == self.stored_order:
pass
Expand Down
5 changes: 5 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ def test_position_assignation(self, reader):
reader[0]
assert_almost_equal(reader.ts.positions, new_positions)

def test_timeseries_warns_deprecation(self, reader):
with pytest.warns(DeprecationWarning, match="MemoryReader.timeseries "
"inclusive"):
reader.timeseries(start=0, stop=3, step=1)


class TestMemoryReaderVelsForces(object):
@staticmethod
Expand Down