Plot series data silently truncated to float32 when passed as numpy array (should be float64/double)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend, data-visualization
Research direction
Start in src/mvPyUtils.cpp at ToDoubleVect() and the BufferViewFunctionsFloat() helper near line 1016. Trace how buffer-protocol values are converted and check whether existing tests cover float64 NumPy inputs. Done means float64 arrays passed to plot series preserve precision like Python float lists, with a regression test for the reported truncation.
Written by the indexing model from the issue text.
Description
Dear PyGui version:
2.3.1
Python version:
3.14/3.x
Operating system:
All platforms
My issue/question:
Summary
When passing a numpy.ndarray with dtype=float64 (or any buffer-protocol object) to plot series functions like dpg.add_line_series() / dpg.set_value(), the data is silently truncated to float32 precision internally, even though ImPlot's template instantiation and DPG's draw layer both correctly use double. This causes real-world timestamp data (e.g. Unix timestamps ~1.7e15 microseconds) to collapse into a flat line due to float32's ~7 significant-digit limit.
Python list[float] and tuple[float] work correctly and preserve full float64 precision.
Root Cause
In src/mvPyUtils.cpp, the ToDoubleVect() function uses BufferViewFunctionsFloat() when processing buffer-protocol inputs (numpy arrays), instead of a Double version.
mvPyUtils.cpp:1322 — inside ToDoubleVect():
else if (PyObject_CheckBuffer(value)) { ... auto BufferViewer = BufferViewFunctionsFloat(buffer_info); // ← BUG: should be Double variant ... items.emplace_back(BufferViewer(buffer_info, i)); }
mvPyUtils.cpp:1016-1017 — the float viewer forcibly downcasts float64:
else if (strcmp(bufferView.format, "d") == 0) // float64 numpy array return [](Py_buffer& b, Py_ssize_t i) { return (float)*((double*)b.buf + i); // ← cast to float32, then promoted back to double };
There is no BufferViewFunctionsDouble() helper in DPG at all.
Affected code chain (all correctly use double — except the one above)
<style>.c1 { border-bottom-color:rgba(115, 115, 115, 0.12); border-bottom-style:solid; border-bottom-width:0.8px; border-left-color:rgba(115, 115, 115, 0.12); border-left-style:solid; border-left-width:0.8px; border-right-color:rgba(115, 115, 115, 0.12); border-right-style:solid; border-right-width:0.8px; border-spacing:0px; border-top-color:rgba(115, 115, 115, 0.12); border-top-style:solid; border-top-width:0.8px; color:rgb(23, 23, 23); font-family:'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', Roboto, sans-serif; font-size:14px; line-height:22px; text-decoration-color:rgb(23, 23, 23) } .c2 { background-color:rgba(115, 115, 115, 0.08); border-bottom-color:rgba(115, 115, 115, 0.12); border-left-color:rgba(115, 115, 115, 0.12); border-right-color:rgba(115, 115, 115, 0.12); border-spacing:0px; border-top-color:rgba(115, 115, 115, 0.12); color:rgb(23, 23, 23); font-family:'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', Roboto, sans-serif; font-size:14px; height:36.8px; line-height:22px; text-decoration-color:rgb(23, 23, 23); width:726.4px } .c3 { border-bottom-color:rgba(115, 115, 115, 0.12); border-left-color:rgba(115, 115, 115, 0.12); border-right-color:rgba(115, 115, 115, 0.12); border-spacing:0px; border-top-color:rgba(115, 115, 115, 0.12); color:rgb(23, 23, 23); font-family:'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', Roboto, sans-serif; font-size:14px; line-height:22px; text-decoration-color:rgb(23, 23, 23) } .c4 { border-bottom-color:rgba(115, 115, 115, 0.12); border-bottom-style:solid; border-bottom-width:0.8px; border-left-color:rgb(23, 23, 23); border-right-color:rgb(23, 23, 23); border-spacing:0px; border-top-color:rgb(23, 23, 23); color:rgb(23, 23, 23); font-family:'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', Roboto, sans-serif; font-size:14px; font-weight:600; height:36.8px; line-height:20px; padding-bottom:8px; padding-left:12px; padding-right:12px; padding-top:8px; text-align:left; text-decoration-color:rgb(23, 23, 23); width:493.087px } </style> Layer -- Reproduction: `import numpy as np import dearpygui.dearpygui as dpg222 real price ticks with microsecond timestamps (shape: (2, 222))
arr[0] = prices ~868.62 → 868.86 (22 distinct values)
arr[1] = microsecond timestamps ~1.79436319e15 (222 distinct values)
arr = np.load("a.npz")['arr_0']
ts = arr[1] / 1e6 # still float64, values ~1.79436319e9
px = arr[0] # float64
print("Unique ts (numpy array):", len(set(ts.tolist()))) # 222 distinct values
print("Unique px (numpy array):", len(set(px.tolist()))) # 22 distinct values
dpg.create_context()
with dpg.window():
with dpg.plot():
xax = dpg.add_plot_axis(dpg.mvXAxis)
yax = dpg.add_plot_axis(dpg.mvYAxis)
dpg.add_line_series(ts, px, parent=yax, label="numpy array") # ← BUG: flat line
# dpg.add_line_series(ts.tolist(), px.tolist(), parent=yax) # ← WORKS: jagged curve
dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()`
Steps to reproduce:
import numpy as np
import dearpygui.dearpygui as dpg
222 real price ticks with microsecond timestamps (shape: (2, 222))
arr[0] = prices ~868.62 → 868.86 (22 distinct values)
arr[1] = microsecond timestamps ~1.79436319e15 (222 distinct values)
arr = np.load("a.npz")['arr_0']
ts = arr[1] / 1e6 # still float64, values ~1.79436319e9
px = arr[0] # float64
print("Unique ts (numpy array):", len(set(ts.tolist()))) # 222 distinct values
print("Unique px (numpy array):", len(set(px.tolist()))) # 22 distinct values
dpg.create_context()
with dpg.window():
with dpg.plot():
xax = dpg.add_plot_axis(dpg.mvXAxis)
yax = dpg.add_plot_axis(dpg.mvYAxis)
dpg.add_line_series(ts, px, parent=yax, label="numpy array") # ← BUG: flat line
# dpg.add_line_series(ts.tolist(), px.tolist(), parent=yax) # ← WORKS: jagged curve
dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
Expected behavior:
Expected behavior
Both numpy.ndarray(float64) and list[float] inputs should produce identical, precision-preserving curves.
Actual behavior
numpy.ndarray(float64) → flat line (all X values collapse to same float32) list[float] → correct jagged curve Workaround Convert numpy arrays to Python lists before passing: Python dpg.add_line_series(ts.tolist(), px.tolist()) dpg.set_value("line_tag", ts.tolist(), px.tolist())
Screenshots:
N/A
Standalone, minimal, complete and verifiable example:
import numpy as np
import dearpygui.dearpygui as dpg
# 222 real price ticks with microsecond timestamps (shape: (2, 222))
# arr[0] = prices ~868.62 → 868.86 (22 distinct values)
# arr[1] = microsecond timestamps ~1.79436319e15 (222 distinct values)
arr = np.load("a.npz")['arr_0']
ts = arr[1] / 1e6 # still float64, values ~1.79436319e9
px = arr[0] # float64
print("Unique ts (numpy array):", len(set(ts.tolist()))) # 222 distinct values
print("Unique px (numpy array):", len(set(px.tolist()))) # 22 distinct values
dpg.create_context()
with dpg.window():
with dpg.plot():
xax = dpg.add_plot_axis(dpg.mvXAxis)
yax = dpg.add_plot_axis(dpg.mvYAxis)
dpg.add_line_series(ts, px, parent=yax, label="numpy array") # ← BUG: flat line
# dpg.add_line_series(ts.tolist(), px.tolist(), parent=yax) # ← WORKS: jagged curve
dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
[a.zip](https://github.com/user-attachments/files/34668931/a.zip)
- Dominant language
- C++
- Stars
- 15.7k
- Forks
- 790
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hoffstadt/DearPyGui
-
state: pending type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
state: pending type: improvement
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
state: pending type: bug
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
state: pending type: improvement
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
state: pending type: bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
All issues in hoffstadt/DearPyGui
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
bot-triaged module: correctness (silent) module: fft triage review
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
patrickjquinn/Marathon-Shell#84 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
sav-oss-org/ptusa_main#1610 ·
Maintainers usually reply within 1 day