1

DolphinDB server version : 2.00.9.1 2023.02.20 ; linux64

python==3.7

DDB package version : 1.30.21.1

Problem Description:

I want to use ddb.tableAppender() to write a Python dataframe to a DolphinDB table. A column in the table is of type DECIMAL. But after uploading, the data is changed.

enter image description here

damie
  • 412
  • 2
  • 7
  • I noticed that this also occurred for your id_1, and both only has a decimal precision of 3 compared to the rest which has a precision of 4, and after transferring all of them have a precision of 4. Could this be related? – Shorn Apr 06 '23 at 03:03

1 Answers1

1

According to the Python API for DolphinDB (5.4.2), when uploading tables containing objects of Python decimal.Decimal(), you must ensure that all values in the columns of DECIMAL type have the same decimal digits. Otherwise, it will return a value with the same digits as the first row of value. Your first row of data has four decimal digits, so error will occur when you upload data with 3 decimal digits.

To solve the problem, you can try the following script:

price_list = [Decimal(str(round(random.uniform(1, 1000),4))).quantize(decimal.Decimal("0.0000")) for _ in range(10)] + [Decimal(str(round(random.uniform(1, 100),4))).quantize(decimal.Decimal("0.0000")) for _ in range(10)]
YaN
  • 407
  • 1
  • 6