Skip to content

[BUG]pandas == condition fails #4258

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
letpat opened this issue Apr 2, 2025 · 2 comments
Open

[BUG]pandas == condition fails #4258

letpat opened this issue Apr 2, 2025 · 2 comments
Labels
bug Something isn't working max-repo mojo Issues that are related to mojo

Comments

@letpat
Copy link

letpat commented Apr 2, 2025

Bug description

Actual behavior

With a very simple dataframe (one column col1 and 3 rows),
res = df[df['col1'] == 2]
throws exception :
Unhandled exception caught during execution: False
mojo: error: execution exited with a non-zero result: 1
or
Unhandled exception caught during execution: <cyfunction item_from_zerodim at 0x7f50ea1cdf20> returned a result with an exception set
mojo: error: execution exited with a non-zero result: 1

Expected behavior

With same dataframe,
res = df[(df['col1'] >= 2) & (df['col1'] <= 2)]

works perfectly and return expected rows

Steps to reproduce

from python import Python

def main():
    pd = Python.import_module("pandas")
    data = Python.dict()
    data['col1'] = [1,2,3]
    df = pd.DataFrame(data)
    res = df[df['col1'] == 2]
    print(res)

System information

  • magic 07.2
  • mojo 25.2.0 (26172dfe)
  • pandas 2.2.3
@letpat letpat added bug Something isn't working max-repo mojo Issues that are related to mojo labels Apr 2, 2025
@rcghpge
Copy link
Contributor

rcghpge commented Apr 5, 2025

I started probing around to get an idea of Mojo’s compiler design with your use case. A generic Python object in Python does not translate 1:1 in Mojo yet. Until the compiler is open sourced, I would build helper functions as a workaround or leverage Mojo’s capabilities to do the same thing.

Example maybe of some utils for Python

from python import Python, PythonObject, TypedPythonObject

fn py_int(val: Int) raises -> PythonObject:
    var builtins = Python.import_module("builtins")
    return builtins.__getattr__("int").__call__(val)

fn py_str(text: String) raises -> PythonObject:
    return builtins.__getattr__("str").__call__(text)

@letpat
Copy link
Author

letpat commented Apr 6, 2025

Thanks for the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working max-repo mojo Issues that are related to mojo
Projects
None yet
Development

No branches or pull requests

2 participants