Slice indexing of python objects?
- 主要言語
- Julia
- スター
- 1.5k
- フォーク
- 186
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I'm trying to use [GridSpec](https://matplotlib.org/api/gridspec_api.html#matplotlib.gridspec.GridSpec) in matplotlib with PyCall, and ran into this error:
```julia
julia> using PyCall, PyPlot
# Make a GridSpec object
julia> gs_main = PyPlot.matplotlib[:gridspec][:GridSpec](1, 2)
PyObject
# In python, you can use slice indexing on a GridSpec object to make subplots
# However, the naive way of going about this doesn't work:
julia> gs_main[1:2]
ERROR: MethodError: no method matching getindex(::PyObject, ::UnitRange{Int64})
Closest candidates are:
getindex(::PyObject, ::Symbol) at /home/glynch/.julia/packages/PyCall/rUul9/src/PyCall.jl:294
getindex(::PyObject, ::AbstractString) at /home/glynch/.julia/packages/PyCall/rUul9/src/PyCall.jl:283
getindex(::PyObject, ::Integer) at /home/glynch/.julia/packages/PyCall/rUul9/src/PyCall.jl:755
...
Stacktrace:
[1] top-level scope at none:0
# Manually indexing with slice objects does work, however
julia> gs_main[:__getitem__](pybuiltin(:slice)(0, 2))
PyObject
```
Is there a more straight-forward way of accomplishing this?
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
Reproduce the GridSpec example from the issue, then inspect the getindex methods in PyCall.jl around lines 283, 294, and 755. Compare the failing Julia range expression with the working __getitem__ call using pybuiltin(:slice); done means an idiomatic range-based index works for this Python object without breaking the existing symbol, string, or integer cases.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- julia, python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100