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

[BUG] deprecated_kwargs (list[str]) in v0.24 raises type object not subscriptable error #1200

Closed
zykezero opened this issue Nov 14, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@zykezero
Copy link

zykezero commented Nov 14, 2022

Brief Description

The addition of deprecated_kwargs in version 0.23 causes a type object not subscriptable error.

System Information

I'm using Python 3.8.12 on a sagemaker instance. I'm pretty sure this is the issue, that my company has us locked at 3.8.12 right now. Selecting the v.0.23 does solve the problem.

I'm sorry if this isn't enough information at the moment, let me know if you need anything else.

Error

TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_18038/2902872131.py in <cell line: 1>()
----> 1 import janitor

~/anaconda3/envs/python3/lib/python3.8/site-packages/janitor/__init__.py in <module>
      7 
      8 from .accessors import *  # noqa: F403, F401
----> 9 from .functions import *  # noqa: F403, F401
     10 from .io import *  # noqa: F403, F401
     11 from .math import *  # noqa: F403, F401

~/anaconda3/envs/python3/lib/python3.8/site-packages/janitor/functions/__init__.py in <module>
     17 
     18 
---> 19 from .add_columns import add_columns
     20 from .also import also
     21 from .bin_numeric import bin_numeric

~/anaconda3/envs/python3/lib/python3.8/site-packages/janitor/functions/add_columns.py in <module>
      1 import pandas_flavor as pf
      2 
----> 3 from janitor.utils import check, deprecated_alias
      4 import pandas as pd
      5 from typing import Union, List, Any, Tuple

~/anaconda3/envs/python3/lib/python3.8/site-packages/janitor/utils.py in <module>
    214 
    215 def deprecated_kwargs(
--> 216     *arguments: list[str],
    217     message: str = (
    218         "The keyword argument '{argument}' of '{func_name}' is deprecated."

TypeError: 'type' object is not subscriptable
@zykezero zykezero changed the title deprecated_kwargs (list[str]) in v0.23 raises type object not subscriptable error deprecated_kwargs (list[str]) in v0.24 raises type object not subscriptable error Nov 14, 2022
@Zeroto521
Copy link
Member

Zeroto521 commented Nov 14, 2022

Python 3.8 doesn't directly support this syntax.

  • In python 3.8, it could add from __future__ import __annotations__ to avoid raising error.
  • Another solution is using python 3.9.

Currently janitor is trying to compat with multi-environments.

@zykezero
Copy link
Author

Fully understood as it is as I expected.
Would love to be on 3.9 my company isn't there yet unfortunately. In the meantime I'll keep it locked.

@Zeroto521 Zeroto521 changed the title deprecated_kwargs (list[str]) in v0.24 raises type object not subscriptable error [BUG] deprecated_kwargs (list[str]) in v0.24 raises type object not subscriptable error Nov 15, 2022
@Zeroto521 Zeroto521 added the bug Something isn't working label Nov 15, 2022
@jwalton3141
Copy link

I'm wondering whether this issue should be reopened?

PyPI and the GitHub README specify Python >= 3.6, so not being unable to import janitor from Python 3.8.* would be unexpected.

@xujiboy
Copy link
Contributor

xujiboy commented Nov 19, 2022

In python 3.8, it could add from __future__ import __annotations__ to avoid raising error.

May I know how to make this work for python 3.8? I tried adding this line on the top of my import block but got SyntaxError:

  Input In [13]
    from __future__ import __annotations__
    ^
SyntaxError: future feature __annotations__ is not defined

BTW, I tried from __future__ import annotations on the top before importing janitor but still get the same TypeError: 'type' object is not subscriptable

@Zeroto521
Copy link
Member

@xujiboy my mistake
it should be from __future__ import annotations

@xujiboy
Copy link
Contributor

xujiboy commented Nov 19, 2022

Thanks @Zeroto521 I tried from __future__ import annotations on the top before importing janitor but still get the same TypeError: 'type' object is not subscriptable

@Zeroto521
Copy link
Member

@xujiboy only for py3.8, lower versions don't support this feature.

$ python
Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 05:59:00) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a: list[int] = [1, 2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
>>> from __future__ import annotations
>>> a: list[int] = [1, 2]
>>> a
[1, 2]

@xujiboy
Copy link
Contributor

xujiboy commented Nov 21, 2022

Thanks @Zeroto521 for providing the example. I am able to reproduce your code snipt but import janitor still errors out:

Python 3.8.13 (default, Oct 21 2022, 23:50:54)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from __future__ import annotations

In [2]: a: list[str] = ['2', ]

In [3]: import janitor
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 import janitor

File ~/miniconda3/envs/eda/lib/python3.8/site-packages/janitor/__init__.py:9, in <module>
      5 import lazy_loader as lazy
      8 from .accessors import *  # noqa: F403, F401
----> 9 from .functions import *  # noqa: F403, F401
     10 from .io import *  # noqa: F403, F401
     11 from .math import *  # noqa: F403, F401

File ~/miniconda3/envs/eda/lib/python3.8/site-packages/janitor/functions/__init__.py:19, in <module>
      1 """
      2 # General Functions
      3
   (...)
     15 7. Never import utils.
     16 """
---> 19 from .add_columns import add_columns
     20 from .also import also
     21 from .bin_numeric import bin_numeric

File ~/miniconda3/envs/eda/lib/python3.8/site-packages/janitor/functions/add_columns.py:3, in <module>
      1 import pandas_flavor as pf
----> 3 from janitor.utils import check, deprecated_alias
      4 import pandas as pd
      5 from typing import Union, List, Any, Tuple

File ~/miniconda3/envs/eda/lib/python3.8/site-packages/janitor/utils.py:216, in <module>
    207     if not func(df, *args, **kwargs) == func(
    208         func(df, *args, **kwargs), *args, **kwargs
    209     ):
    210         raise ValueError(
    211             "Supplied function is not idempotent for the given DataFrame."
    212         )
    215 def deprecated_kwargs(
--> 216     *arguments: list[str],
    217     message: str = (
    218         "The keyword argument '{argument}' of '{func_name}' is deprecated."
    219     ),
    220     error: bool = True,
    221 ) -> Callable:
    222     """
    223     Used as a decorator when deprecating function's keyword arguments.
    224
   (...)
    244         keyword arguments.  # noqa: DAR402
    245     """
    247     def decorator(func):

TypeError: 'type' object is not subscriptable

Is this reproducible on your end? Or are you able to import janitor without a problem?

@Zeroto521
Copy link
Member

Zeroto521 commented Nov 21, 2022

@xujiboy you can try this branch.
It worked fine with my local py38 env.

I found three places need to add from __future__ import annotations:

  • janitor/utils.py
  • janitor/functions/conditional_join.py
  • janitor/functions/utils.py

@xujiboy
Copy link
Contributor

xujiboy commented Nov 21, 2022

@Zeroto521 thanks for the prompt response. So it's my understanding that if currently I want to consume pyjanitor 0.24 through pypi, I need to use python 3.9+. If I have to stick with python 3.8 then I need to install the mentioned branch locally.

@Zeroto521
Copy link
Member

Yes, as you said.

For Python version, I prefer to use the latest version 3.11.
It can speed up pure Python code.
The latest Pandas version compats 3.11.
So janitor is also compatable with 3.11

And this issue will be fixed at pyjanitor 0.24.1

@Zeroto521 Zeroto521 pinned this issue Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants