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

pl.Enum Bug / Incorrect and Kernel crashed #15738

Closed
2 tasks done
Julian-J-S opened this issue Apr 18, 2024 · 1 comment · Fixed by #15740
Closed
2 tasks done

pl.Enum Bug / Incorrect and Kernel crashed #15738

Julian-J-S opened this issue Apr 18, 2024 · 1 comment · Fixed by #15740
Assignees
Labels
A-dtype-categorical Area: categorical data type bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@Julian-J-S
Copy link
Contributor

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

for t in [
    pl.UInt8,
    pl.UInt16,
    pl.UInt32,
    pl.UInt64,
    pl.Int8,
    pl.Int16,
    pl.Int32,
    pl.Int64,
]:
    print(t)
    s = pl.Series([0, 1, 2], dtype=t).cast(pl.Enum(["a", "b", "c"]))  # This does NOT error
    try:
        # print(s.to_list())  # >>>>>>>>>>>>>>>>>> this crashes the kernel!!!!!!!!!!!!!!!!!!!!!!!!!
        print(s) # This given an Exception!
    except BaseException as e:
        print(e)

Log output

UInt8
assertion failed: i < self.len()
UInt16
assertion failed: i < self.len()
UInt32
shape: (3,)
Series: '' [enum]
[
	"a"
	"b"
	"c"
]
UInt64
shape: (3,)
Series: '' [enum]
[
	"a"
	"a"
	"b"
]
Int8
assertion failed: i < self.len()
Int16
assertion failed: i < self.len()
Int32
shape: (3,)
Series: '' [enum]
[
	"a"
	"b"
	"c"
]
Int64
shape: (3,)
Series: '' [enum]
[
	"a"
	"a"
	"b"
]

Issue description

Exception & Wrong results

converting an int other than 32bit to an pl.Enum either

  • crashes when printing for 8/16 bit ints with assertion failed: i < self.len() or
  • wrong result ["a", "a", "c"] instead of ["a", "b", "c"] (even worse because you might not realize this!)

Kernel Crash

converting from 8/16 bit int to Enum and then calling s.to_list() crashes the kernel

Expected behavior

  • conversion should work for all integers
  • conversion should be correct(!) for 64bit ints
  • no kernel crash

Installed versions

--------Version info---------
Polars:               0.20.21
Index type:           UInt32
Platform:             Windows-10-10.0.19045-SP0
Python:               3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
hvplot:               0.9.1
matplotlib:           <not installed>
nest_asyncio:         1.5.7
numpy:                1.26.3
openpyxl:             <not installed>
pandas:               2.2.0
pyarrow:              14.0.0
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@Julian-J-S Julian-J-S added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Apr 18, 2024
@reswqa reswqa added the A-dtype-categorical Area: categorical data type label Apr 18, 2024
@reswqa reswqa mentioned this issue Apr 18, 2024
2 tasks
@reswqa reswqa added P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels Apr 18, 2024
@reswqa reswqa self-assigned this Apr 18, 2024
@reswqa
Copy link
Collaborator

reswqa commented Apr 18, 2024

Thank you for your detailed report. I'll have a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dtype-categorical Area: categorical data type bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants