Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

TypeError for handle Bool values in deep call chain.

Aperta
#1,033 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
julia, python
Ambito
tooling

Direzione di ricerca

Riproducete il callback annidato Julia-to-Python usando l’esempio fornito con sequentialfs e custom_score, quindi esaminate src/pyfncall.jl intorno alla riga 43 e src/pyeval.jl intorno alla riga 12. Confrontate il callback diretto con il percorso sklearn SequentialFeatureSelector e stabilite il comportamento previsto per la catena di chiamate che fallisce.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Environment:

  • Windows 11
  • Julia 1.7.3 (2022-05-06)
  • PyCall v1.94.1

Hello, when I use PyCall to pass a Julia function into a Python function, it seems that PyCall does not handle the Bool (true & false) values correctly.

The call chain is seemly like this:

JuliaFunA(JuliaFunB())
  |
  |->Pythonfun(JuliaFunB())

Specifically, I use Python's sklearn.feature_selection.SequentialFeatureSelector to do some feature selection. and in this selector, it gets an argument scoring which is a callable function. So in my Julia code, I use pystring py""" """ to wrap the selector and pass my Julia function into it. Here is my code:

function sequentialfs(mdl, fun, X, y)
    X = Array(X)
    y = Array(y)

    score = fun(mdl, X, y)
    # j = fun(y)

    py"""
    import sklearn.feature_selection as fs
    def test(mdl, fun, X, y):
        score = fun(mdl, X, y)  # situation 1: the fun can run well if been called from here
        return score
        # sfs = fs.SequentialFeatureSelector(
        #     mdl,
        #     n_features_to_select="auto",
        #     direction="forward",
        #     scoring=fun  # situation 2: the fun cannot run if been passed deeper. 
        # )
        # sfs.fit(X, y)
        # return sfs.get_support(indices=true)
    """
    score = py"test"(mdl, fun, X, y)
    return score
end

function custom_score(estimator, X, y_true)
    y_pred = estimator.predict(X)  # Python sklearn predict function
    score = 1 - sum(abs.(y_pred - y_true)) / length(y_true)
    return score
end

iris_X, iris_y = get_some_data()
mdl = function_return_a_sklearn_classifier(iris_X, iris_y)
sequentialfs(mdl, custom_score, iris_X, iris_y)

In situation 1, if the fun (julia -> julia -> Python and run) could be called well, in situation 2, the fun (julia -> julia -> Python -> Python) does not run well, and there is a Python TypeError:

ERROR: PyError ($(Expr(:escape, :(ccall(#= C:\Users\Public\xxxxxx\.julia\dev\PyCall\src\pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'NameError'>
NameError("name 'true' is not defined")
File "C:\Users\xxxxxx\TongYuan\.julia\dev\PyCall\src\pyeval.jl", line 12, in test
ns = PyDict{String,PyObject}()
Lingua principale
Julia
Stelle
1.5k
Fork
186
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaPy/PyCall.jl

Tutte le issue di JuliaPy/PyCall.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.