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

Feature Request: Support indexing into python objects #1041

Open
schlichtanders opened this issue Jun 25, 2023 · 4 comments
Open

Feature Request: Support indexing into python objects #1041

schlichtanders opened this issue Jun 25, 2023 · 4 comments

Comments

@schlichtanders
Copy link

schlichtanders commented Jun 25, 2023

I am using pandas with PyCall.jl and would like to write something like

mysubset = df[df["colname"] == "value"]

looking into the code
https://github.com/JuliaPy/PyCall.jl/blob/master/src/PyCall.jl#L349-L361
it seems that this is just not supported currently (because of some legacy where indexing was used instead of dot access)

@schlichtanders
Copy link
Author

I can imagine something like

Base.getindex(o::PyObject, s) = py"$o[$s]"
Base.setindex!(o::PyObject, v, s) = py"$o[$s] = $v"

@stevengj
Copy link
Member

In the meantime, you can use PythonCall.jl, which supports this.

@schlichtanders
Copy link
Author

This is not completely true. PythonCall.jl has indeed difficulties with the mentioned example because of comparisons between python object (series) and julia object ("value"). you need to use the @py macro if you want this to work with PythonCall.jl to the best of my knowledge.

I rather prefer to use native julia syntax, which is indeed the main reason I am going for PyCall.jl when calling Python from Julia.

@fabiensatalia
Copy link

Came here to request the same, in fact I would be happy to "just" be able to select rows from a pandas data frame, e.g. df[[1,2]] to select the first two rows

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

No branches or pull requests

3 participants