Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions panel/tests/widgets/test_trend_indicator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import random

import numpy as np
import pandas as pd

from panel import (
Column, Param, Row, WidgetBox, state,
)
Expand All @@ -26,6 +29,21 @@ def test_trend_auto_value(document, comm):
assert model.value_change == ((4000/3900) - 1)


def test_trend_date_range_x_axis(document, comm):
data = pd.DataFrame({
"Date": pd.date_range(start="2020-01-01", periods=5, freq="ME"),
"Sales": [100, 120, 150, 130, 110],
})

trend = Trend(data=data, plot_x="Date", plot_y="Sales")
model = trend.get_root(document, comm)

x_data = model.source.data["Date"]
assert len(x_data) == 5
np.testing.assert_array_equal(x_data, np.arange(5, dtype=float))
assert model.value == 110


def test_trend_auto_value_stream(document, comm):
data = {"x": [1, 2, 3, 4, 5], "y": [3800, 3700, 3800, 3900, 4000]}

Expand Down
9 changes: 8 additions & 1 deletion panel/widgets/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,14 @@ def _get_data(self):
return None, {self.plot_x: [], self.plot_y: []}
elif isinstance(self.data, dict):
return self.data, self.data
return self.data, ColumnDataSource.from_df(self.data)
processed = ColumnDataSource.from_df(self.data)
if (
self.plot_x in getattr(self.data, 'columns', []) and
np.issubdtype(self.data[self.plot_x].dtype, np.datetime64)
):
processed = dict(processed)
processed[self.plot_x] = np.arange(len(self.data), dtype=float)
Comment thread
philippjfr marked this conversation as resolved.
Outdated
return self.data, processed

def _init_params(self):
props = super()._init_params()
Expand Down
Loading