ValueError: Unknown protobuf attr type
执行代码时出错。 我有一个数据存储区实体,它具有Date类型的属性。 存储在特定行的实体中的示例日期属性值是2016-01-03(19:00:00.000)EDT
我正在执行的代码是根据大于2016-01-01的日期过滤实体值。 知道代码有什么问题
错误
1 | ValueError: Unknown protobuf attr type <type 'datetime.date'> |
码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import pandas as pd import numpy as np from datetime import datetime from google.cloud import datastore from flask import Flask,Blueprint app = Flask(__name__) computation_cron= Blueprint('cron.stock_data_transformation', __name__) @computation_cron.route('/cron/stock_data_transformation') def cron(): ds = datastore.Client(project="earningspredictor-173913") query = ds.query(kind='StockPrice') query.add_filter('date', '>', datetime.strptime("2016-01-01", '%Y-%m-%d').date()) dataframe_data = [] temp_dict = {} for q in query.fetch(): temp_dict["stock_code"] = q["stock_code"] temp_dict["date"] = q["date"] temp_dict["ex_dividend"] = q["ex_dividend"] temp_dict["split_ratio"] = q["split_ratio"] temp_dict["adj_open"] = q["adj_open"] temp_dict["adj_high"] = q["adj_high"] temp_dict["adj_low"] = q["adj_low"] temp_dict["adj_close"] = q["adj_close"] temp_dict["adj_volume"] = q["adj_volume"] dataframe_data.append(temp_dict) sph = pd.DataFrame(data=dataframe_data,columns=temp_dict.keys()) # print sph.to_string() query = ds.query(kind='EarningsSurprise') query.add_filter('act_rpt_date', '>', datetime.strptime("2016-01-01", '%Y-%m-%d').date()) dataframe_data = [] temp_dict = {} for q in query.fetch(): temp_dict["stock_code"] = q["stock_code"] temp_dict["eps_amount_diff"] = q["eps_amount_diff"] temp_dict["eps_actual"] = q["eps_actual"] temp_dict["act_rpt_date"] = q["act_rpt_date"] temp_dict["act_rpt_code"] = q["act_rpt_code"] temp_dict["eps_percent_diff"] = q["eps_percent_diff"] dataframe_data.append(temp_dict) es = pd.DataFrame(data=dataframe_data,columns=temp_dict.keys()) |
您似乎使用的是通用
对于
- JSON
- field name:
timestampValue - type: string (RFC 3339 formatted, with milliseconds, for instance
2013-05-14T00:01:00.234Z )- Protocol buffer
- field name:
timestamp_value - type:
Timestamp - Sort order: Chronological
- Notes: When stored in Cloud Datastore, precise only to microseconds; any additional precision is rounded down.
因此,在设置/比较这些属性时,尝试使用按指定格式化的字符串(或protobuf Timestamp的整数?),而不是
注意:这仅基于文档,我自己没有使用通用库。