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

Appending series of type pl.Categorical("lexical") may incorrectly set the sorted flag #19900

Open
2 tasks done
siddharth-vi opened this issue Nov 21, 2024 · 0 comments · May be fixed by #20414
Open
2 tasks done

Appending series of type pl.Categorical("lexical") may incorrectly set the sorted flag #19900

siddharth-vi opened this issue Nov 21, 2024 · 0 comments · May be fixed by #20414
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@siddharth-vi
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

import polars as pl

s= pl.Series("a",["z", "z", "k", "a", "b"],pl.Categorical("lexical"))
print(s.is_sorted())
#False
print(s.cat.uses_lexical_ordering())
#True

s1=s[[0]]
s2=s[[1]]
s3=s[[2]]
s4=s[[3]]
s5=s[[4]]

s1.append(s2)
s1.append(s3)
s1.append(s4)
s1.append(s5)

print(s1.is_sorted())
#True
print(s1.cat.uses_lexical_ordering())
#True

print(s==s1)
#Series: 'a' [bool]
# [
# 	true
# 	true
# 	true
# 	true
# 	true
# ]

print(s1.flags)
#{'SORTED_ASC': True, 'SORTED_DESC': False}

Log output

No response

Issue description

If we split a pl.Categorical("lexical") series and then append them all back the sorted flag gets set as true.

Expected behavior

Appended series should not have sorted flag as true

Installed versions

--------Version info---------
Polars:              1.14.0
Index type:          UInt32
Platform:            Linux-5.15.0-112-generic-x86_64-with-glibc2.35
Python:              3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
boto3                <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                2.1.2
openpyxl             <not installed>
pandas               2.2.3
pyarrow              <not installed>
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@siddharth-vi siddharth-vi added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
1 participant