python - great_expectations:expect_column_values_to_match_json_schema 不将 json 模式作为输入
问题描述
我正在尝试调用
expect_column_values_to_match_json_schema
按照
jschema = {
"type" : "object",
"properties" : {
"xyz" : {"type" : "string"}
}
}
df_ge.expect_column_values_to_match_json_schema(column='abc',json_schema=jschema,row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')
但是我收到了这个错误
File "/some/path/lib/python3.7/site-packages/great_expectations/dataset/pandas_dataset.py", line 1554, in matches_json_schema
val_json = json.loads(val)
File "/usr/lib/python3.7/json/__init__.py", line 341, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not dict
所以我尝试了
df_ge.expect_column_values_to_match_json_schema(column='abc',json_schema=json.loads(str(jschema)),row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')
但后来我明白了
df_ge.expect_column_values_to_match_json_schema(column='pg',json_schema=json.loads(str(pgschema)),row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
我怎样才能创建一个合适的 json 对象来提供给这个方法?
解决方案
没有“JSON 对象”之类的东西。JSON 是一种序列化格式,所以唯一可以是 JSON 的就是一串字节。这样的字符串可以用 的相反来创建json.loads
,即json.dumps
:
df_ge.expect_column_values_to_match_json_schema(column='pg',json_schema=json.dumps(pgschema),row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')
推荐阅读
- ms-access - Access - 何时对表进行查询
- c# - 通过参数强制接口到属性
- sql - 标量变量必须在 SQL 变量中声明
- gdb - GDB 的“信息共享库”显示所有库的相同“发件人”和“收件人”地址
- java - Tomcat 和 JSP 的 ClassCastException
- html - 在多个 HTML 复选框列表中显示所选项目
- python - 如何获取熊猫数据框列在给定月份的天数?
- python - 为 Pandas Dataframe.to_html() 的单列着色
- php - User::find($user_id) 的 Laravel 分页问题
- apache-kafka - 卡夫卡消费者再平衡:飞行中的消息处理被中止