dolphindb / api_python3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

数据类型为Object传入输出时确推断为double?????

hugo2046 opened this issue · comments

commented

Ubuntu-22.04
python版本3.8.18
pandas 1.5.3
doblindb 1.30.22.6

appender: ddb.PartitionedTableAppender = ddb.PartitionedTableAppender( ddb_conn.db_path, "stock", "trade_date", ddb_conn.pool ) appender.append(data)
报错:

RuntimeError Traceback (most recent call last)
Cell In[25], line 4
1 appender: ddb.PartitionedTableAppender = ddb.PartitionedTableAppender(
2 ddb_conn.db_path, "stock", "trade_date", ddb_conn.pool
3 )
----> 4 appender.append(data)

File d:\anaconda3\envs\qlib_env\lib\site-packages\dolphindb\session.py:1201, in PartitionedTableAppender.append(self, table)
1199 if self.pool.is_shutdown():
1200 raise RuntimeError("DBConnectionPool has been shut down.")
-> 1201 return self.appender.append(table)

RuntimeError: in append: column [code], expect type SYMBOL, got type DOUBLE

但是data.info()数据类型为:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5318 entries, 0 to 5317
Data columns (total 23 columns):

Column Non-Null Count Dtype


0 adj_open 5318 non-null float64
1 vwap 5318 non-null float64
2 amount 5318 non-null int32
3 adj_close 5318 non-null float64
4 high 5318 non-null float64
5 code 5318 non-null object
6 adj_factor 5318 non-null float64
7 open 5318 non-null float64
8 pct_chg 5318 non-null float64
9 adj_low 5318 non-null float64
10 change 5318 non-null float64
11 trade_status_code 5318 non-null float64
12 limit 5318 non-null float64
13 close 5318 non-null float64
14 volume 5318 non-null int32
15 adj_preclose 5318 non-null float64
16 stopping 5318 non-null float64
17 trade_date 5318 non-null datetime64[ns]
18 pre_close 5318 non-null float64
19 trade_status 5318 non-null object
20 low 5318 non-null float64
21 adjclose_backward 5318 non-null float64
22 adj_high 5318 non-null float64
dtypes: datetime64ns, float64(18), int32(2), object(2)
memory usage: 914.2+ KB
code类在py中的数据类型为object但是报错却说其类型为DOUBEL????这是为什么

对于 object 这种不明确的类型,在上传到 DDB server 时,内部会遍历每个元素,去做一个类型判断,估计是您这列的数据被推断成 DOUBLE 了。可以参考一下:https://github.com/dolphindb/api_python3/blob/master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.1_PROTOCOL_DDB.md#32-vector

commented

对于 object 这种不明确的类型,在上传到 DDB server 时,内部会遍历每个元素,去做一个类型判断,估计是您这列的数据被推断成 DOUBLE 了。可以参考一下:master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.1_PROTOCOL_DDB.md#32-vector

您好,我找到原因了,是传入的字段名称顺序与表结构上的位置不一致造成的,需要按照表结构顺序排一个顺序,您说的哪个问题我也排查过,确实也是需要注意的。谢谢回复