-
Notifications
You must be signed in to change notification settings - Fork 659
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 warnings for API changes #1403
Conversation
@@ -106,6 +106,8 @@ | |||
universe2 = mda.Universe(PSF, coordinates, format=MemoryReader, order='afc') | |||
|
|||
|
|||
.. _create-in-memory-trajectory-with-AnalysisFromFunction: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that I can reference the anchor in the docs in package/MDAnalysis/core/Timeseries.py – it can be removed again in 0.17.0 when Timeseries.py is gone. This is the standard way to do cross references in sphinx.
I do not like the idea of removing the docs (see below) but rather point to alternatives. This will be the last release with the feature. If you ever need to tell someone which release to use then you point them to 0.16.2. And then the docs for the feature should still exist.
warnings.warn(('The Timeseries module and TimeseriesCollection will be ' | ||
'removed in the 0.17 release. See issue #1372 ' | ||
'https://github.com/MDAnalysis/mdanalysis/issues/1373'), | ||
DeprecationWarning) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaves the warning levels of other modules like ipython untouched?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume so... it's what we have been doing elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In [15]: warnings.catch_warnings?
Init signature: warnings.catch_warnings(self, record=False, module=None)
Docstring:
A context manager that copies and restores the warnings filter upon
exiting the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good just checking
package/MDAnalysis/core/__init__.py
Outdated
@@ -30,7 +30,8 @@ | |||
:class:`~MDAnalysis.core.groups.AtomGroup` and return another | |||
:class:`~MDAnalysis.core.groups.AtomGroup`. | |||
|
|||
:mod:`~MDAnalysis.Timeseries` are a convenient way to analyse trajectories. | |||
:mod:`~MDAnalysis.core.Timeseries` are a convenient way to analyse | |||
trajectories. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this due to deprecations already here? We should already point people to use the analysis frame work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do.
""" | ||
def __getitem__(self, item): | ||
# DEPRECATED in 0.16.2 | ||
# REMOVE in 1.0 | ||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't there be warnings issues here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will annoy the hell of people, won't it? I can't use the decorator because __getitem__
is used for other stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, adding, the warnings only show up once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we only have a warning when item
is a string right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
*Instant selectors* will be removed in the 1.0 release. See issue `#1377 | ||
<https://github.com/MDAnalysis/mdanalysis/issues/1377>`_ for more details. | ||
|
||
Atoms can also be accessed in a Pythonic fashion by using the atom name as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're deprecating something, can we remove the documentation for it? Someone might skip the dep warning, then read about this great feature they want to use forevermore....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to remove docs of a feature in the last release where the feature exists. If anyone really wants the feature then they should still have the docs. Deprecation warnings should be enough. And it's already in its own section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confused the instant selectors with the Timeseries regarding "last release". But I still think that it should be documented for as long as it is available.
(Otherwise the deprecated:: 0.16.2 tag makes little sense: it says when it was deprecated, not when it was removed. The removal also kills the docs and possible leaves a versionchanged:: 1.0.0 behind.)
@richardjgowers how do import MDAnalysis as mda; from MDAnalysisTests.datafiles import PSF
u = mda.Universe(PSF)
print(u.residues.LYS)
print(u.segments.s4AKE) I don't see a |
OK my pushes are now showing up in the PR's that is weird |
Thanks, I will merge with what I am working on. |
You should be able to use the |
@richardjgowers how does this end up in |
... or have a look at the PR and comment, that is probably going to be more helpful. Or push to the PR. I have to do other things for the rest of the day, sorry. |
Note: At least two of the new tests are currently failing because I didn't know how add depreactions:
|
I am trying #1403 (comment). |
Thanks to @richardjgowers for insights #1403 (comment)
With decorators on the methods in #1403 (comment) and explicit warnings in one other place (for the Segment.r1 selectors) it now seems to be working as expected, at least locally. I will rebase and clean up. |
Interactive work will be annoying for a while because TAB completion on ``u.residues.` will trigger the deprecation warning. Depending on settings for the warning filter, this will only show up once, though, and then deprecation warnings for real use will be swallowed. Let's see how it goes... if it is too annoying we can fix it (... how? ...) as we go along. |
eca6a61
to
3acba3c
Compare
- instant selectors AtomGroup['<name>'], AtomGroup.<name>, ResidueGroup.<name>, Segment.<segid>, Segment.r<resid>, SegmentGroup.<segid> emit warnings - added tests - updated docs with detailed deprecation and alternatives Thanks to @richardjgowers for insights #1403 (comment)
Rebased and force-pushed. If travis is green (any my local docs look ok) then this is good to go from my side. |
sphinx fails, not sure why:
The only change is |
I fixed all sphinx warnings. |
If you use the numpy |
Can someone else please have a look at the failing tests. I don't find where we trigger the warnings that fail for the old numpy version build. |
@@ -409,6 +411,9 @@ def getattr__(atomgroup, name): | |||
raise AttributeError("'{0}' object has no attribute '{1}'".format( | |||
atomgroup.__class__.__name__, name)) | |||
|
|||
@deprecate(message="Instant selector AtomGroup['<name>'] or AtomGroup.<name> " | |||
"is deprecated and will be removed in 1.0. " | |||
"Use AtomGroup.select_atoms('name <name>') instead.") | |||
def _get_named_atom(group, name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now issue a warning for atoms.ChainIDs
or atoms.segids
. I don't think that was the indented effect. @richardjgowers could you have a look please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kain88-de I added a test if AtomGroup.segids raises a warning and locally the test passes.
In python and ipython, no warning is raised for atoms.segids
:
Python 2.7.13 (default, Apr 25 2017, 03:00:22)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MDAnalysis as mda; from MDAnalysisTests.datafiles import PSF; import MDAnalysisTests
>>> w = MDAnalysisTests.make_Universe(("resids", "resnames", "segids", "names"))
>>> w
<Universe with 125 atoms>
>>> w.atoms.segids
array(['SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA',
'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA',
'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA', 'SegA',
'SegA', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB',
'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB',
'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB', 'SegB',
'SegB', 'SegB', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC',
'SegC', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC',
'SegC', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC', 'SegC',
'SegC', 'SegC', 'SegC', 'SegD', 'SegD', 'SegD', 'SegD', 'SegD',
'SegD', 'SegD', 'SegD', 'SegD', 'SegD', 'SegD', 'SegD', 'SegD',
'SegD', 'SegD', 'SegD', 'SegD', 'SegD', 'SegD', 'SegD', 'SegD',
'SegD', 'SegD', 'SegD', 'SegD', 'SegE', 'SegE', 'SegE', 'SegE',
'SegE', 'SegE', 'SegE', 'SegE', 'SegE', 'SegE', 'SegE', 'SegE',
'SegE', 'SegE', 'SegE', 'SegE', 'SegE', 'SegE', 'SegE', 'SegE',
'SegE', 'SegE', 'SegE', 'SegE', 'SegE'], dtype=object)
>>>
>>> w.atoms['AAA']
/Volumes/Data/oliver/Biop/Projects/Methods/MDAnalysis/mdanalysis/package/MDAnalysis/core/groups.py:1520: DeprecationWarning: Using the [] operator with strings is deprecated and will be removed in 1.0. Please use `select_atoms('name AAA')` instead.
category=DeprecationWarning)
/Volumes/Data/oliver/Biop/Projects/Methods/MDAnalysis/mdanalysis/package/MDAnalysis/core/groups.py:1522: DeprecationWarning: `_get_named_atom` is deprecated!
Instant selector AtomGroup['<name>'] or AtomGroup.<name> is deprecated and will be removed in 1.0. Use AtomGroup.select_atoms('name <name>') instead.
return self._get_named_atom(item)
<Atom 1: AAA of resname RsA, resid 1 and segid SegA>
Could you please paste what code you've been running?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adopted _get_named_atom
to also print the requested name. That way I found out we apparently use it for more then just atom names
from MDAnalysisTests import make_Universe
import warnings
warnings.simplefilter('always')
req_attrs = {'resnames': 'UNK',
'resids': 1,
'names': 'X',
'tempfactors': 0.0,
}
attrs = list(req_attrs.keys())
u = make_Universe(attrs, trajectory=True)
u.atoms.write('test.crd')
output
/home/max/foss/molecular-dynamics/mdanalysis/mdanalysis/package/MDAnalysis/core/groups.py:1539: DeprecationWarning: `_get_named_atom` is deprecated!
Instant selector AtomGroup['<name>'] or AtomGroup.<name> is deprecated and will be removed in 1.0. Use AtomGroup.select_atoms('name <name>') instead.
return self._get_named_atom(attr)
chainIDs
/home/max/foss/molecular-dynamics/mdanalysis/mdanalysis/package/MDAnalysis/core/groups.py:1539: DeprecationWarning: `_get_named_atom` is deprecated!
Instant selector AtomGroup['<name>'] or AtomGroup.<name> is deprecated and will be removed in 1.0. Use AtomGroup.select_atoms('name <name>') instead.
return self._get_named_atom(attr)
segids
/home/max/foss/molecular-dynamics/mdanalysis/mdanalysis/package/MDAnalysis/coordinates/CRD.py:229: UserWarning: Supplied AtomGroup was missing the following attributes: tempfactors. These will be written with default values.
"".format(miss=', '.join(missing_topology)))
This is running with numpy 1.12.1
package/MDAnalysis/core/groups.py
Outdated
@@ -1513,6 +1513,9 @@ def __getitem__(self, item): | |||
# | |||
# u.atoms['HT1'] access, otherwise default | |||
if isinstance(item, string_types): | |||
warnings.warn("Using the [] operator with strings is deprecated." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kain88-de thanks for adding it back – I must have removed it accidentally when I rebased.
@kain88-de thanks for working on the PR and figuring out the deprecation decorator/sphinx issue as well as putting back 13bc527. |
It is weird that the OLD_NUMPY tests fail but the new ones do not – if anything, the new ones should fail, too! It seems that What should we do? Create a copy of |
- closes #1383 - included deprecations: - #1373 Timeseries (targeted for 0.17) Note that the deprecation for core.Timeseries will always show up; this is deliberate so that users WILL see it as it will be gone in the next release! - #1377 Quick selectors (target 1.0) - #782 flags (target 1.0) - updated CHANGELOG
- improved installation instructions (minimal/full install for pip, always full install for conda; also added entry on installation of tests) - analysis landing page: better explained optional packages, removed scipy as example and replaced with sklearn and HOLE.
- removed imports in core and MDAnalysis - replaced MDAnalysis.collection with a mock object that issues warnings and raises NotImplementedError - added a test for MDAnalysis.collection
- instant selectors AtomGroup['<name>'], AtomGroup.<name>, ResidueGroup.<name>, Segment.<segid>, Segment.r<resid>, SegmentGroup.<segid> emit warnings - added tests - updated docs with detailed deprecation and alternatives Thanks to @richardjgowers for insights #1403 (comment)
It turns out that with this warning in place we raise two deprecation warnings because we also have a warning on _get_named_atom(item). Example output: >>> w.atoms['AAA'] .../mdanalysis/package/MDAnalysis/core/groups.py:1520: DeprecationWarning: Using the [] operator with strings is deprecated and will be removed in 1.0. Please use `select_atoms('name AAA')` instead. category=DeprecationWarning) .../mdanalysis/package/MDAnalysis/core/groups.py:1522: DeprecationWarning: `_get_named_atom` is deprecated! Instant selector AtomGroup['<name>'] or AtomGroup.<name> is deprecated and will be removed in 1.0. Use AtomGroup.select_atoms('name <name>') instead. return self._get_named_atom(item) <Atom 1: AAA of resname RsA, resid 1 and segid SegA>
This allows code to use the `getattr` function and only throw an error if the requested attribute is an atom name.
1abebb2
to
a9f9655
Compare
@richardjgowers if this solves the problem we might be able to just do a normal style release. |
It seems to have worked. The old numpy test isn't failing anymore. |
@richardjgowers do you want to merge this? @jbarnoud did you see anything else that needs to be fixed? |
I should probably clone it and play with it locally to check it. Give me a few hours to testdrive it |
The full test times out, everything else seems to be ok. @richardjgowers you have the honor of merging... |
- instant selectors AtomGroup['<name>'], AtomGroup.<name>, ResidueGroup.<name>, Segment.<segid>, Segment.r<resid>, SegmentGroup.<segid> emit warnings - added tests - updated docs with detailed deprecation and alternatives Thanks to @richardjgowers for insights #1403 (comment)
Fixes #1383
Changes made in this Pull Request:
Note that the deprecation for core.Timeseries will always show up;
this is deliberate so that users WILL see it as it will be gone in
the next release!
PR Checklist