### Download DolphinDB Set Data Source: https://github.com/dolphindb/api_python3/blob/master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.1_PROTOCOL_DDB.md This example shows how to download a Set type from DolphinDB and its conversion to a Python set. Only specific DolphinDB types are supported for Set conversion. ```python >>> re = s.run("set(1..5)") >>> re {1, 2, 3, 4, 5} >>> type(re) ``` -------------------------------- ### Download DolphinDB Matrix Data Source: https://github.com/dolphindb/api_python3/blob/master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.1_PROTOCOL_DDB.md This example demonstrates how to download a Matrix type from DolphinDB. The downloaded data includes row and column names if they exist; otherwise, None is used. ```python >>> s.run(""" ... mtx = 1..12$4:3; ... mtx.rename!(1 2 3 4, `c1`c2`c3); ... mtx ... ") [array([[ 1, 5, 9], [ 2, 6, 10], [ 3, 7, 11], [ 4, 8, 12]], dtype=int32), array([1, 2, 3, 4], dtype=int32), array(['c1', 'c2', 'c3'], dtype=object)] ``` -------------------------------- ### Download DolphinDB Dict Data Source: https://github.com/dolphindb/api_python3/blob/master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.1_PROTOCOL_DDB.md This example demonstrates downloading a Dict type from DolphinDB and its conversion to a Python dictionary. Keys are converted as Scalars, and values are converted based on their data form and type. ```python >>> re = s.run('''{"a": 123, "b": [1.1, 2.2]}''') >>> re {'b': array([1.1, 2.2]), 'a': 123} >>> type(re) ``` -------------------------------- ### Enable PROTOCOL_PICKLE with Session and DBConnectionPool Source: https://github.com/dolphindb/api_python3/blob/master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.2_PROTOCOL_PICKLE.md Initialize a DolphinDB session or connection pool using the PROTOCOL_PICKLE. In the current version, PROTOCOL_DEFUALT is equivalent to PROTOCOL_PICKLE, making it the default serialization/deserialization protocol. ```python import dolphindb as ddb import dolphindb.settings as keys s = ddb.session(protocol=keys.PROTOCOL_PICKLE) s.connect("localhost", 8848, "admin", "123456") pool = ddb.DBConnectionPool("localhost", 8848, "admin", "123456", 10, protocol=keys.PROTOCOL_PICKLE) ``` -------------------------------- ### Deserialize Table Data with PROTOCOL_PICKLE Source: https://github.com/dolphindb/api_python3/blob/master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.2_PROTOCOL_PICKLE.md Download Table data using PROTOCOL_PICKLE. The dtypes for columns in the resulting pandas DataFrame are mapped from DolphinDB types. Note that certain DolphinDB types like BLOB, DECIMAL32/64, and specific Array Vectors are not supported. ```python >>> re = s.run("table([1, NULL] as a, [2012.01.02, 2012.01.05] as b)") >>> re a b 0 1.0 2012-01-02 1 NaN 2012-01-05 >>> re['a'].dtype float64 >>> re['b'].dtype datetime64[ns] ``` -------------------------------- ### Deserialize Matrix Data with PROTOCOL_PICKLE Source: https://github.com/dolphindb/api_python3/blob/master/README_CN_NEW/3_AdvancedOperations/3.1_DataTypeCasting/3.1.2_PROTOCOL_PICKLE.md When downloading Matrix data using PROTOCOL_PICKLE, the result is a list containing three elements: the actual data as a NumPy ndarray, and optionally row and column names. For time-related data types, the dtype is consistently datetime64[ns]. ```python >>> s.run("date([2012.01.02, 2012.02.03])$1:2") [array([['2012-01-02T00:00:00.000000000', '2012-02-03T00:00:00.000000000']], dtype='datetime64[ns]'), None, None] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.