polars icon indicating copy to clipboard operation
polars copied to clipboard

'ABCMeta' object is not subscriptable in latest release 0.15.12

Open LachlanStuart opened this issue 2 years ago • 1 comments

Polars version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of Polars.

Issue description

I just started getting this exception, which seems to be caused by the latest release on PyPI (0.15.12):

> ipython                                                          [0]
Python 3.8.12 (default, Jul  5 2022, 16:46:20)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from polars import api
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [1], line 1
----> 1 from polars import api

File ~/dev/venv/lib/python3.8/site-packages/polars/__init__.py:14
     11     # this is only useful for documentation
     12     warnings.warn("polars binary missing!")
---> 14 from polars import api
     15 from polars.build_info import build_info
     16 from polars.cfg import Config

File ~/dev/venv/lib/python3.8/site-packages/polars/api.py:8
      5 from typing import Callable, TypeVar
      6 from warnings import warn
----> 8 from polars.internals import DataFrame, Expr, LazyFrame, Series
     10 __all__ = [
     11     "register_expr_namespace",
     12     "register_dataframe_namespace",
     13     "register_lazyframe_namespace",
     14     "register_series_namespace",
     15 ]
     17 # do not allow override of polars' own namespaces (as registered by '_accessors')

File ~/dev/venv/lib/python3.8/site-packages/polars/internals/__init__.py:14
      1 """
      2 Core Polars functionality.
      3
   (...)
      6 `import polars.internals as pli`. The imports below are being shared across this module.
      7 """
      8 from polars.internals.anonymous_scan import (
      9     _deser_and_exec,
     10     _scan_ds,
     11     _scan_ipc_fsspec,
     12     _scan_parquet_fsspec,
     13 )
---> 14 from polars.internals.batched import BatchedCsvReader
     15 from polars.internals.dataframe import DataFrame, wrap_df
     16 from polars.internals.expr import (
     17     Expr,
     18     expr_to_lit_or_expr,
     19     selection_to_pyexpr_list,
     20     wrap_expr,
     21 )

File ~/dev/venv/lib/python3.8/site-packages/polars/internals/batched.py:9
      7 from polars.datatypes import PolarsDataType, py_type_to_dtype
      8 from polars.internals.type_aliases import CsvEncoding
----> 9 from polars.utils import (
     10     _prepare_row_count_args,
     11     _process_null_values,
     12     format_path,
     13     handle_projection_columns,
     14 )
     16 try:
     17     from polars.polars import PyBatchedCsv

File ~/dev/venv/lib/python3.8/site-packages/polars/utils.py:42
     40 # note: reversed views don't match as instances of MappingView
     41 if sys.version_info >= (3, 8):
---> 42     _reverse_mapping_views = tuple(
     43         type(reversed(cast(Reversible[Any], view)))
     44         for view in ({}.keys(), {}.values(), {}.items())
     45     )
     48 if TYPE_CHECKING:
     49     from polars.internals.type_aliases import SizeUnit, TimeUnit

File ~/dev/venv/lib/python3.8/site-packages/polars/utils.py:43, in <genexpr>(.0)
     40 # note: reversed views don't match as instances of MappingView
     41 if sys.version_info >= (3, 8):
     42     _reverse_mapping_views = tuple(
---> 43         type(reversed(cast(Reversible[Any], view)))
     44         for view in ({}.keys(), {}.values(), {}.items())
     45     )
     48 if TYPE_CHECKING:
     49     from polars.internals.type_aliases import SizeUnit, TimeUnit

TypeError: 'ABCMeta' object is not subscriptable

I'm running Python 3.8.12

Reproducible example

from polars import api
# or
import polars as pl

Expected behavior

Polars should import without error

Installed versions

# I can't run this because the import fails

LachlanStuart avatar Jan 05 '23 17:01 LachlanStuart

Hmm.. @alexander-beedie could this be related to the lazy imports? 🫤

ritchie46 avatar Jan 05 '23 17:01 ritchie46

Ok, I can confirm that I can import.

>>> pl.show_versions()
---Version info---
Polars: 0.15.12
Index type: UInt32
Platform: Linux-5.15.0-56-generic-x86_64-with-glibc2.31
Python: 3.9.12 (main, Apr  5 2022, 06:56:58) 
[GCC 7.5.0]
---Optional dependencies---
pyarrow: 10.0.1
pandas: 1.4.4
numpy: 1.23.2
fsspec: 2022.5.0
connectorx: <not installed>
xlsx2csv: <not installed>
matplotlib: 3.5.3

ritchie46 avatar Jan 05 '23 18:01 ritchie46

@ritchie46 - No, not lazy imports. I checked when Key/Value/Item views became reversible, and I'm still pretty sure it was 3.8; perhaps it's the Reversible[Any] type annotation - I'm going to quickly shuffle through the docs and double-check each, as my money is on one of them...

Our tests run on 3.7 and and 3.11 where we know it works, so let's just set the version-gate at 3.11 instead of 3.8 for now. The number of people actually wanting to load reversed dictionary iterators has to be almost completely irrelevant 😅

alexander-beedie avatar Jan 05 '23 18:01 alexander-beedie

You mean the if sys.version_info >= (3, 8): to if sys.version_info >= (3, 11): right?

I can do this now, quickly patch and call it a day?

ritchie46 avatar Jan 05 '23 18:01 ritchie46

You mean the if sys.version_info >= (3, 8): to if sys.version_info >= (3, 11): right? I can do this now, quickly patch and call it a day?

Exactly; gets my vote. Will need a matching version update (3,8) => (3,11) in the test_from_generator_or_iterable unit test.

alexander-beedie avatar Jan 05 '23 18:01 alexander-beedie

Alright. Thanks for the swift response. Makes my evening. ;)

The number of people actually wanting to load reversed dictionary iterators has to be almost completely irrelevant sweat_smile

I am certain it will be lower than the # of people wanting to import polars. :D

ritchie46 avatar Jan 05 '23 18:01 ritchie46

Alright. Thanks for the swift response. Makes my evening. ;)

Lol... no problem, apologies that it slipped through. I guess we have a bit of a hole in the tests between 3.7 & 3.11; I keep finding myself wanting to write walrus operators := everywhere and having to stop myself, hah.

alexander-beedie avatar Jan 05 '23 18:01 alexander-beedie

Lol... no problem, apologies that it slipped through. I guess we have a bit of a hole in the tests between 3.7 & 3.11; I keep finding myself wanting to write walrus operators := everywhere and having to stop myself, hah.

Yes, this is a reminder that we should have import tests on the other python versions.

ritchie46 avatar Jan 05 '23 18:01 ritchie46

Found it; it is the Reversible[Any] type annotation; mypy clearly hates me this week. According to PEP585 that is only valid typing from (3,9) onwards. But I'm perfectly happy to leave it at (3,11) until I can confirm with my own two eyes that this is definitely true - so maybe at the weekend ;)

alexander-beedie avatar Jan 05 '23 18:01 alexander-beedie

v0.15.13 works again for me. Thank you very much for the quick fix!

LachlanStuart avatar Jan 05 '23 19:01 LachlanStuart