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

Importing ABCs from collections.abc #2607

Merged
merged 5 commits into from
Mar 12, 2020
Merged

Conversation

abhiShandy
Copy link
Contributor

@abhiShandy abhiShandy commented Mar 10, 2020

Fixes #2605

Changes made in this Pull Request:

  • Importing ABCs from collections.abc instead of deprecated direct method in collections.MutableMapping

I ran lib/test_util.py::TestFlattenDict locally to confirm that the corresponding deprecation warning is eliminated.

PR Checklist

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

@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

Merging #2607 into develop will decrease coverage by 0.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2607      +/-   ##
===========================================
- Coverage    90.71%   90.60%   -0.12%     
===========================================
  Files          174      174              
  Lines        23549    23256     -293     
  Branches      3072     3066       -6     
===========================================
- Hits         21363    21070     -293     
  Misses        1565     1565              
  Partials       621      621              
Impacted Files Coverage Δ
package/MDAnalysis/lib/util.py 88.16% <100.00%> (-0.11%) ⬇️
package/MDAnalysis/auxiliary/base.py 88.19% <0.00%> (-0.74%) ⬇️
package/MDAnalysis/coordinates/chain.py 87.37% <0.00%> (-0.59%) ⬇️
package/MDAnalysis/coordinates/TRZ.py 83.46% <0.00%> (-0.38%) ⬇️
package/MDAnalysis/coordinates/base.py 93.46% <0.00%> (-0.36%) ⬇️
package/MDAnalysis/coordinates/DMS.py 88.23% <0.00%> (-0.34%) ⬇️
package/MDAnalysis/coordinates/GMS.py 85.41% <0.00%> (-0.30%) ⬇️
package/MDAnalysis/coordinates/INPCRD.py 90.62% <0.00%> (-0.29%) ⬇️
package/MDAnalysis/coordinates/GSD.py 86.95% <0.00%> (-0.28%) ⬇️
package/MDAnalysis/coordinates/TXYZ.py 90.10% <0.00%> (-0.22%) ⬇️
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53ccf6d...b103096. Read the comment docs.

@abhiShandy
Copy link
Contributor Author

Travis CI failed since my change is not reverse compatible with Python 2.7
Should I make it reverse compatible?

@IAlibay
Copy link
Member

IAlibay commented Mar 10, 2020

@abhiShandy unfortunately MDA must support py2.7 until at least v1.0.0 (if I'm remembering the roadmap correctly). An option that would cover py2.7 through tto 3.8 would be appreciated if possible.

@lilyminium
Copy link
Member

Do we need MutableMapping? So far as I can tell, flatten_dict is only used once in groups.py, on a dict.

res = dict()
if isinstance(topattrs, (string_types, bytes)):
attr=topattrs
if isinstance(topattrs, bytes):
attr = topattrs.decode('utf-8')
ta = getattr(self, attr)
return {i: self[ta == i] for i in set(ta)}
else:
attr = topattrs[0]
ta = getattr(self, attr)
for i in set(ta):
if len(topattrs) == 1:
res[i] = self[ta == i]
else:
res[i] = self[ta == i].groupby(topattrs[1:])
return util.flatten_dict(res)

@abhiShandy
Copy link
Contributor Author

abhiShandy commented Mar 10, 2020

Do we need MutableMapping? So far as I can tell, flatten_dict is only used once in groups.py, on a dict.

res = dict()
if isinstance(topattrs, (string_types, bytes)):
attr=topattrs
if isinstance(topattrs, bytes):
attr = topattrs.decode('utf-8')
ta = getattr(self, attr)
return {i: self[ta == i] for i in set(ta)}
else:
attr = topattrs[0]
ta = getattr(self, attr)
for i in set(ta):
if len(topattrs) == 1:
res[i] = self[ta == i]
else:
res[i] = self[ta == i].groupby(topattrs[1:])
return util.flatten_dict(res)

Good point.

  • changed it to isinstance(v, dict) to check if it's nested.
  • Removed unnecessary collections from that file.

Locally, lib/test_util and core/test_groups passed with Python 3.8

@abhiShandy
Copy link
Contributor Author

@MDAnalysis/gsoc-mentors can someone review this?

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Please also

  • add yourself to AUTHORS
  • add a note to Fixes in CHANGELOG (referencing the issue)

@orbeckst
Copy link
Member

Please ping me @orbeckst for a final review when you have addressed my review and all tests pass. Thank you for your contribution!

@orbeckst orbeckst self-assigned this Mar 12, 2020
@abhiShandy
Copy link
Contributor Author

@orbeckst it's ready

@orbeckst orbeckst merged commit 9740d80 into MDAnalysis:develop Mar 12, 2020
@orbeckst
Copy link
Member

Thank you very much, @abhiShandy !

@fiona-naughton fiona-naughton added defect deprecation Deprecated functionality to give advance warning for API changes. labels Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect deprecation Deprecated functionality to give advance warning for API changes. GSOC Starter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation warning from "collections" library
5 participants