Python:TypeError:预期字节,发现(尝试做嵌套元数据)
我想将嵌套的元数据如下:
schema = pa.schema([pa.field('Id', pa.string(), metadata={"pg_dtype": {"dtype": "int[36]", "pkey": "1"}}),
pa.field('Name', pa.string(), metadata={"pg_dtype": {"dtype": "varchar[20]", "pkey": "1"}})])
但是获得此错误,
TypeError: expected bytes, dict found
我指的是这个嵌套的示例以制作嵌套的元数据
people = {'type': {'name': 'John', 'age': '27', 'sex': 'Male'},
'type': {'name': 'Marie', 'age': '22', 'sex': 'Female'}}
I want to make nested metadata as below:
schema = pa.schema([pa.field('Id', pa.string(), metadata={"pg_dtype": {"dtype": "int[36]", "pkey": "1"}}),
pa.field('Name', pa.string(), metadata={"pg_dtype": {"dtype": "varchar[20]", "pkey": "1"}})])
but getting this error
TypeError: expected bytes, dict found
I refer to this nested dict example to make nested metadata
people = {'type': {'name': 'John', 'age': '27', 'sex': 'Male'},
'type': {'name': 'Marie', 'age': '22', 'sex': 'Female'}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
metadata
应为dict
带有键和值的 str (或 bytes )。您不能嵌套尺寸。您必须将嵌套的dict(pg_dtypes
)倾倒为JSON字符串:这有效,但我不确定这是PG拾取它的正确格式。
metadata
should be adict
with keys and values asstr
(orbytes
). You can't have a nested dict in it. You'd have to dump the nested dict (pg_dtypes
) as a json string:This works but I'm not sure it's the right format of pg to pick it up.