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

Using pandas categorical as index leads to max recursion depth error #3361

Closed
twiecki opened this issue Jan 27, 2019 · 9 comments
Closed

Using pandas categorical as index leads to max recursion depth error #3361

twiecki opened this issue Jan 27, 2019 · 9 comments

Comments

@twiecki
Copy link
Member

twiecki commented Jan 27, 2019

Described in #2380

Not sure where the error is from (probably theano somewhere) or if we can catch it. In any case, the work-around is easy: convert the index to ints.

@MarcoGorelli
Copy link
Contributor

@twiecki do you have a reproducible example for this?

@michaelosthege
Copy link
Member

Closing because there's no MRE here or in the other thread.

If someone runs into this issue with the latest version, please reopen it and provide a minimum reproducible example that we can make into a test case.

@ivar-rummelhoff
Copy link

Please reopen this issue. The problem still exists in PyMC 5.8.1. Here is a small example:

import pymc as pm
import pandas as pd
with pm.Model():
    indices = ['a', 'b', 'c']
    df = pd.DataFrame([1, 2, 3], index=indices, columns=['n'])
    n = pm.ConstantData('n', df.n)
    print(n[indices])

Result: RecursionError: maximum recursion depth exceeded in comparison
Replacing ConstantData with MutableData makes no difference.

@wd60622
Copy link
Contributor

wd60622 commented Nov 11, 2023

This can also be reproduced with

import pytensor.tensor as pt

x = pt.as_tensor_variable([1.0, 2.0])

# RecursionError
x["a"]
x[["a", "b"]]

So it seems like a pytensor item

@ricardoV94
Copy link
Member

Why would strings work as indexes?

@wd60622
Copy link
Contributor

wd60622 commented Nov 11, 2023

Why would strings work as indexes?

good question. Pandas supports so maybe it could be something someone does by mistake

x = pd.Series([1, 2], index=["a", "b"])
x["a"] # 1

@ivar-rummelhoff
Copy link

If PyMC does not support this, then that is what the error message should say. I ran into this issue with data from a relational database with string primary key; but I find Pandas (especially in combination with PyMC) so confusing that I have gone back to using NumPy arrays.

@ricardoV94
Copy link
Member

Right yes we can try to have a better message.

PyMC can't really use pandas objects other than converting then to numpy arrays.

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 6, 2024

Closing as stale, feel free to reopen if still relevant

Btw, the error message if desired, should be implemented in PyTensor

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

No branches or pull requests

6 participants