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 warnings for API changes #1403

Merged
merged 15 commits into from
Jun 21, 2017

Conversation

orbeckst
Copy link
Member

@orbeckst orbeckst commented Jun 15, 2017

Fixes #1383

Changes made in this Pull Request:

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@orbeckst orbeckst added this to the 0.16.x milestone Jun 15, 2017
@orbeckst orbeckst mentioned this pull request Jun 16, 2017
4 tasks
@kain88-de kain88-de mentioned this pull request Jun 16, 2017
11 tasks
@@ -106,6 +106,8 @@
universe2 = mda.Universe(PSF, coordinates, format=MemoryReader, order='afc')


.. _create-in-memory-trajectory-with-AnalysisFromFunction:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this added?

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good just checking

@@ -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.
Copy link
Member

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

Copy link
Member Author

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
#
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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....

Copy link
Member Author

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.

Copy link
Member Author

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.)

@orbeckst
Copy link
Member Author

@richardjgowers how do ResidueGroup and SegmentGroup do their instant selector magic?

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 __getattr__ in them or in GroupBase so I don't know how to attach deprecation warnings.

@kain88-de
Copy link
Member

OK my pushes are now showing up in the PR's that is weird

@orbeckst
Copy link
Member Author

Thanks, I will merge with what I am working on.

@richardjgowers
Copy link
Member

@orbeckst

You should be able to use the @deprecate decorator on those and it'll only appear if you use them

@orbeckst
Copy link
Member Author

@richardjgowers how does this end up in __getattr__?

@orbeckst
Copy link
Member Author

... 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.

@orbeckst
Copy link
Member Author

Note: At least two of the new tests are currently failing because I didn't know how add depreactions:

MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_AtomGroup_nowarn_getitem_index ... ok
MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_AtomGroup_warn_getattr ... ok
MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_AtomGroup_warn_getitem ... ok
MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_ResidueGroup_warn_getattr_resname ... FAIL
MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_SegmentGroup_nowarn_getitem ... ok
MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_SegmentGroup_warn_getattr ... FAIL
MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_Segment_warn_getattr_rRESNUM ... ok
MDAnalysisTests.core.test_groups.TestInstantSelectorDeprecationWarnings.test_Segment_warn_getattr_resname ... ok

@orbeckst
Copy link
Member Author

I am trying #1403 (comment).

orbeckst added a commit that referenced this pull request Jun 17, 2017
@orbeckst
Copy link
Member Author

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.

@orbeckst
Copy link
Member Author

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.

@orbeckst orbeckst force-pushed the issue-1383-deprecation-warnings branch from eca6a61 to 3acba3c Compare June 17, 2017 01:12
orbeckst added a commit that referenced this pull request Jun 17, 2017
- 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)
@orbeckst
Copy link
Member Author

Rebased and force-pushed.

If travis is green (any my local docs look ok) then this is good to go from my side.

@orbeckst
Copy link
Member Author

sphinx fails, not sure why:

/Volumes/Data/oliver/Biop/Projects/Methods/MDAnalysis/mdanalysis/package/MDAnalysis/core/Timeseries.py:82: DeprecationWarning: The Timeseries module and TimeseriesCollection will be removed in the 0.17 release. See issue #1372 https://github.com/MDAnalysis/mdanalysis/issues/1373
  DeprecationWarning)
reading sources... [100%] index

Warning, treated as error:
/Volumes/Data/oliver/Biop/Projects/Methods/MDAnalysis/mdanalysis/package/MDAnalysis/coordinates/DCD.py:docstring of MDAnalysis.coordinates.DCD.DCDReader.correl:11: (SEVERE/4) Unexpected section title.

Parameters
----------

The only change is @deprecate decorator on DCD.correl.

@kain88-de
Copy link
Member

I fixed all sphinx warnings.

@kain88-de
Copy link
Member

If you use the numpy deprecate decorator sphinx might fail because the decorator changes the docstring. This seems to be problematic for class member functions.

@kain88-de
Copy link
Member

kain88-de commented Jun 17, 2017

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):
Copy link
Member

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.

Copy link
Member Author

@orbeckst orbeckst Jun 17, 2017

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?

Copy link
Member

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

@@ -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."
Copy link
Member Author

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.

@orbeckst
Copy link
Member Author

@kain88-de thanks for working on the PR and figuring out the deprecation decorator/sphinx issue as well as putting back 13bc527.

orbeckst added a commit that referenced this pull request Jun 17, 2017
@orbeckst
Copy link
Member Author

#1403 (comment)

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.

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 _get_named_atom() is not only used for instant selectors but also for other things, e.g., in the CDRWriter or PQRWriter. https://travis-ci.org/MDAnalysis/mdanalysis/jobs/244102138#L1310

What should we do? Create a copy of _get_named_atom() and deprecate one? But I would need @richardjgowers help in figuring out where this goes. I don't fully understand the new topology magic yet...

orbeckst and others added 15 commits June 20, 2017 16:20
- 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.
@kain88-de kain88-de force-pushed the issue-1383-deprecation-warnings branch from 1abebb2 to a9f9655 Compare June 20, 2017 14:20
@kain88-de
Copy link
Member

@richardjgowers if this solves the problem we might be able to just do a normal style release.

@kain88-de
Copy link
Member

It seems to have worked. The old numpy test isn't failing anymore.

@kain88-de
Copy link
Member

@richardjgowers do you want to merge this?

@jbarnoud did you see anything else that needs to be fixed?

@richardjgowers
Copy link
Member

I should probably clone it and play with it locally to check it. Give me a few hours to testdrive it

@orbeckst
Copy link
Member Author

The full test times out, everything else seems to be ok. @richardjgowers you have the honor of merging...

@richardjgowers richardjgowers merged commit e24da32 into develop Jun 21, 2017
@richardjgowers richardjgowers deleted the issue-1383-deprecation-warnings branch June 21, 2017 09:42
richardjgowers pushed a commit that referenced this pull request Jun 21, 2017
- 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)
richardjgowers pushed a commit that referenced this pull request Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add deprecation warnings for API changes
4 participants