JuliaPy / JuliaPy/PyCall.jl

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

Đang mở
#700 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Julia
Star
1.5k
Fork
186
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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:

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:

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...?

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
julia, python, sqlalchemy
Lĩnh vực
databases
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.