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

MAINT: use collections.abc for 3.7 #11733

Merged
merged 3 commits into from Jul 24, 2018
Merged

Conversation

andyfaff
Copy link
Contributor

scipy is getting some issues when trying to test on Python 3.7 because of a DeprecationWarning:

DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working

This PR just changes a few instances of collections.X into collections.abc.X.

_____________________ TestDendrogram.test_dendrogram_plot _____________________
[gw1] win32 -- Python 3.7.0 C:\Python37-x64\python.exe
self = <scipy.cluster.tests.test_hierarchy.TestDendrogram object at 0x0000005E63E60160>
    @pytest.mark.skipif(not have_matplotlib, reason="no matplotlib")
    def test_dendrogram_plot(self):
        for orientation in ['top', 'bottom', 'left', 'right']:
>           self.check_dendrogram_plot(orientation)
orientation = 'top'
self       = <scipy.cluster.tests.test_hierarchy.TestDendrogram object at 0x0000005E63E60160>
C:\Python37-x64\lib\site-packages\scipy\cluster\tests\test_hierarchy.py:822: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Python37-x64\lib\site-packages\scipy\cluster\tests\test_hierarchy.py:842: in check_dendrogram_plot
    ax = fig.add_subplot(221)
C:\Python37-x64\lib\site-packages\matplotlib\figure.py:1239: in add_subplot
    a = subplot_class_factory(projection_class)(self, *args, **kwargs)
C:\Python37-x64\lib\site-packages\matplotlib\axes\_subplots.py:77: in __init__
    self._axes_class.__init__(self, fig, self.figbox, **kwargs)
C:\Python37-x64\lib\site-packages\matplotlib\axes\_base.py:523: in __init__
    self.cla()
C:\Python37-x64\lib\site-packages\matplotlib\axes\_base.py:1032: in cla
    self.set_xlim(0, 1)
C:\Python37-x64\lib\site-packages\matplotlib\axes\_base.py:3110: in set_xlim
    self._process_unit_info(xdata=(left, right))
C:\Python37-x64\lib\site-packages\matplotlib\axes\_base.py:2139: in _process_unit_info
    self.xaxis.update_units(xdata)
C:\Python37-x64\lib\site-packages\matplotlib\axis.py:1463: in update_units
    converter = munits.registry.get_converter(data)
C:\Python37-x64\lib\site-packages\matplotlib\units.py:188: in get_converter
    thisx = safe_first_element(x)
C:\Python37-x64\lib\site-packages\matplotlib\cbook\__init__.py:2347: in safe_first_element
    if isinstance(obj, collections.Iterator):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'Iterator'
    def __getattr__(name):
        # For backwards compatibility, continue to make the collections ABCs
        # through Python 3.6 available through the collections module.
        # Note, no new collections ABCs were added in Python 3.7
        if name in _collections_abc.__all__:
            obj = getattr(_collections_abc, name)
            import warnings
            warnings.warn("Using or importing the ABCs from 'collections' instead "
                          "of from 'collections.abc' is deprecated, "
                          "and in 3.8 it will stop working",
>                         DeprecationWarning, stacklevel=2)
E           DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
name       = 'Iterator'
obj        = <class 'collections.abc.Iterator'>
warnings   = <module 'warnings' from 'C:\\Python37-x64\\lib\\warnings.py'>
C:\Python37-x64\lib\collections\__init__.py:52: DeprecationWarning

@tacaswell tacaswell added this to the v3.1 milestone Jul 22, 2018
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Thanks! After reverting the change to OrderedDict this will be good.

def __init__(self):
self._od = collections.OrderedDict()
self._od = collections.abc.OrderedDict()
Copy link
Member

Choose a reason for hiding this comment

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

OrderedDict is not in abc

@andyfaff
Copy link
Contributor Author

Lets see if this works.

@@ -1714,7 +1715,7 @@ def safe_first_element(obj):

def sanitize_sequence(data):
"""Converts dictview object to list"""
return list(data) if isinstance(data, collections.MappingView) else data
return list(data) if isinstance(data, collections.abc.MappingView) else data
Copy link
Contributor

Choose a reason for hiding this comment

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

need a line break here, the style checker is not happy

@anntzer
Copy link
Contributor

anntzer commented Jul 24, 2018

@tacaswell I think avoiding a warning on Py3.7 makes this worth milestoning for mpl3.0?

@anntzer anntzer modified the milestones: v3.1, v3.0 Jul 24, 2018
@anntzer
Copy link
Contributor

anntzer commented Jul 24, 2018

OSX failure is irrelevant and will be "fixed" (or worked around, at least) by #11763. Allowing myself to remilestone to 3.0 per above.

@anntzer anntzer merged commit cf38546 into matplotlib:master Jul 24, 2018
@anntzer
Copy link
Contributor

anntzer commented Jul 24, 2018

Thanks for the PR.

@tacaswell
Copy link
Member

@meeseeksdev backport to v2.2.x

@lumberbot-app
Copy link

lumberbot-app bot commented Aug 4, 2018

There seem to be a conflict, please backport manually

@tacaswell tacaswell modified the milestones: v2.2.3, v2.2.4 Aug 10, 2018
@toslunar toslunar mentioned this pull request Sep 13, 2018
3 tasks
@timhoffm timhoffm mentioned this pull request Nov 3, 2018
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Sep 5, 2019
MAINT: use collections.abc for 3.7
Conflicts:
   lib/matplotlib/cbook/__init__.py

Added try-except block to handle py2 case
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.

None yet

4 participants