Skip to content

topk().list decodes "infinity" as float #3573

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

Open
gotmog opened this issue Mar 25, 2025 · 2 comments
Open

topk().list decodes "infinity" as float #3573

gotmog opened this issue Mar 25, 2025 · 2 comments
Assignees
Labels
bug Bug

Comments

@gotmog
Copy link

gotmog commented Mar 25, 2025

Version: 5.2.1

Platform: Python 3.13.2

Expected behavior

Calling topk().list() on a topk structure containing the string "infinity" should include the string "infinity" in the results.

>>> import redis as r
>>> redis = r.Redis()
>>> redis.topk().reserve("foo", 10, 20, 20, 0.9)
True
>>> redis.topk().add("foo", "infinity")
[None]
>>> redis.topk().list("foo")
["infinity"]
>>> type(redis.topk().list("foo")[0])
<class 'str'>

Actual behavior

The string "infinity" gets decoded as an inf float value.

>>> import redis as r
>>> redis = r.Redis()
>>> redis.topk().reserve("foo", 10, 20, 20, 0.9)
True
>>> redis.topk().add("foo", "infinity")
[None]
>>> redis.topk().list("foo")
[inf]
>>> type(redis.topk().list("foo")[0])
<class 'float'>
@vladvildanov
Copy link
Collaborator

Thanks for reaching out! We will have a look soon

@petyaslavova
Copy link
Collaborator

The issue is related to the specific word "infinity". In the response parsing we have a postprocessing callback for the list command. It goes through all items and tries to convert each value to int, float or string - in that order. In case of failed conversion, it goes to the next type.
float('infinity') produces valid float object, although in this case it is not the desired behavior.
The same will happen with strings like 'nan', 'inf', '-inf', '-infinity'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants