Developer Solutions

In-depth answers to today's top programming questions.

How to Fix the DolphinDB Python API __DolphinDB_Type__ Pandas UserWarning

June 4, 2026    Source Question

Understanding the Pandas UserWarning in DolphinDB

When uploading a Pandas DataFrame to DolphinDB using the Python API, you might want to enforce specific DolphinDB column types (like converting a string column to a DATETIME or SYMBOL type). The standard way to do this in DolphinDB is by assigning a dictionary to the custom attribute df.__DolphinDB_Type__.

However, doing so triggers the following Pandas UserWarning:

UserWarning: Pandas doesn't allow columns to be created via a new
attribute name - see
https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access

This warning occurs because Pandas intercepts any new attribute assignment on a DataFrame object to prevent users from accidentally trying to create a new column via attribute access (e.g., writing df.new_col = ... instead of df['new_col'] = ...).

While the data uploads successfully, this warning can clutter your logs. Here are the best ways to resolve or work around this issue.

Solution 1: Convert to Native Pandas Types (Recommended)

The cleanest, warning-free approach is to let DolphinDB's Python API automatically map standard Pandas data types to their corresponding DolphinDB types. Instead of passing datetime strings and forcing the DATETIME type via __DolphinDB_Type__, convert the column to a Pandas datetime object using pd.to_datetime() before uploading.

import pandas as pd
import dolphindb as ddb

s = ddb.session()
s.connect("localhost", 8848, "admin", "123456")

df = pd.DataFrame({
    'trade_time': ['2026-05-25 10:00:00', '2026-05-25 10:01:00'],
    'price': [100.5, 101.2],
    'volume': [1000, 2000]
})

# Convert to datetime64[ns] - DolphinDB will automatically map this to DATETIME/TIMESTAMP
df['trade_time'] = pd.to_datetime(df['trade_time'])

s.upload({"df": df})

This method eliminates the need for __DolphinDB_Type__ entirely, preventing the warning from ever being triggered.

Solution 2: Suppress the Pandas Warning Safely

If you are mapping to specialized DolphinDB types (such as MINUTE, SECOND, MONTH, or SYMBOL) that do not have direct, native Pandas equivalents, using __DolphinDB_Type__ is still the correct and official approach supported by DolphinDB.

In this case, you can safely suppress this specific warning using Python's built-in warnings module:

import warnings
import pandas as pd
import dolphindb as ddb

# Suppress the specific Pandas attribute-access UserWarning
warnings.filterwarnings(
    "ignore", 
    category=UserWarning, 
    message=".*columns to be created via a new attribute name.*"
)

df = pd.DataFrame({
    'trade_time': ['2026-05-25 10:00:00', '2026-05-25 10:01:00'],
    'price': [100.5, 101.2],
    'volume': [1000, 2000]
})

# This will no longer output a warning
df.__DolphinDB_Type__ = {
    'trade_time': "DATETIME",
}

s = ddb.session()
s.connect("localhost", 8848, "admin", "123456")
s.upload({"df": df})

Solution 3: Upload and Cast on the Server Side

Another robust alternative is to upload the raw DataFrame as-is, and then use DolphinDB server-side functions to cast the types. This is highly recommended for production pipelines where data schema integrity is critical.

# Upload the raw dataframe
s.upload({"df_temp": df})

# Cast types on the DolphinDB server side
s.run("df = select datetime(trade_time) as trade_time, price, volume from df_temp")

By using server-side casting, you keep your Python code clean, leverage DolphinDB's highly optimized casting engine, and avoid any Pandas-specific warnings.