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

Collections.Mapping is depreciated for python versions >3.10 #41

Open
mvarnold opened this issue Aug 14, 2023 · 1 comment
Open

Collections.Mapping is depreciated for python versions >3.10 #41

mvarnold opened this issue Aug 14, 2023 · 1 comment

Comments

@mvarnold
Copy link

Getting some Attribute Errors when making shifts if using a newer version of python.

 File "/Users/michael/projects/data-mountain-query/data_mountain_query/sentiment_plot.py", line 378, in general_sentiment_shift
    sentiment_shift = sh.WeightedAvgShift(type2freq_1=type2freq_1,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/michael/miniconda3/envs/data-mountain-query/lib/python3.11/site-packages/shifterator/shifts.py", line 59, in __init__
    super().__init__(
  File "/Users/michael/miniconda3/envs/data-mountain-query/lib/python3.11/site-packages/shifterator/shifterator.py", line 72, in __init__
    self.type2score_1, lex_ref = helper.get_score_dictionary(type2score_1)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/michael/miniconda3/envs/data-mountain-query/lib/python3.11/site-packages/shifterator/helper.py", line 156, in get_score_dictionary
    if isinstance(scores, collections.Mapping):
                          ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Mapping'

It's an easy fix, just need to change line 156 in helper.py from

    if isinstance(scores, collections.Mapping):

to

    if isinstance(scores, collections.abc.Mapping):

see this stack overflow post for more: https://stackoverflow.com/questions/69381312/in-vs-code-importerror-cannot-import-name-mapping-from-collections

@mvarnold
Copy link
Author

mvarnold commented Aug 14, 2023

Actually, if you want to make it backward compatible and not deal with different versions of shifterator for different versions of python, I would add something like this:

try:
    from collections.abc import Mapping
except ImportError:
    from collections import Mapping

in the imports and then just edit to have Mapping on line 156

if isinstance(scores, Mapping):

instead of the existing collections.Mapping

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

No branches or pull requests

1 participant