JuliaPy / JuliaPy/PyCall.jl

Can't automatically convert KeyedTuple (from sqlalchemy) to Julia's NamedTuple

オープン
#700 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Julia
スター
1.5k
フォーク
186
PR マージ指標
30日以内にマージされた PR はありません

説明

I use PyCall to call sqlalchemy from Julia, which uses a class called `KeyedTuple` to represent rows resulting from a query and I want to convert those automatically to julia's `NamedTuple`. I expected something like this to work:

```julia
using PyCall

sa = pyimport("sqlalchemy")

pytype_mapping(sa."util"."KeyedTuple", NamedTuple)

Base.convert(::Type{NamedTuple}, o::PyObject) = NamedTuple{Symbol.(o._fields)}([getproperty(o, f) for f in Symbol.(o._fields)])

x = sa.util.KeyedTuple([1, 2, 3], labels=["one", "two", "three"]) # returns (1, 2, 3)

```

This is no surprise, since:

```julia
o = @pycall sa.util.KeyedTuple([1, 2, 3], labels=["one", "two", "three"])::PyObject

pytype_query(o) # Returns `Tuple{Integer,Integer,Integer}`
```

I guess a simple way to make my thing work would be to alter the order in which `pytype_query` does things> I mean first look for a match in the `pytype_queries` array and then proceed with the rest...?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start with the pytype_query and pytype_queries entry points mentioned in the issue, then reproduce the Julia/PyCall example using SQLAlchemy's util.KeyedTuple. Determine whether the type-specific mapping should be checked before the existing tuple handling, and consider the conversion complete when the example produces a NamedTuple with the expected field names and values.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
julia, python, sqlalchemy
領域
databases
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。