Skip to content

Commit a22a7be

Browse files
committed
stocks date to string and test_trendline_on_timeseries fix
1 parent 7d611fb commit a22a7be

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/python/plotly/plotly/data/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ def stocks(indexed=False, datetimes=False, return_type="pandas"):
252252

253253
df = nw.from_native(
254254
_get_dataset("stocks", return_type=return_type), eager_only=True
255-
)
255+
).with_columns(nw.col("date").cast(nw.String()))
256+
256257
if datetimes:
257-
df = df.with_columns(nw.col("date").cast(nw.Datetime(time_unit="ns")))
258+
df = df.with_columns(nw.col("date").str.to_datetime())
258259

259260
if indexed: # then it must be pandas
260261
df = df.to_native().set_index("date")

packages/python/plotly/plotly/tests/test_optional/test_px/test_trendline.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ def test_ols_trendline_slopes():
189189
("ewm", dict(alpha=0.5)),
190190
],
191191
)
192-
def test_trendline_on_timeseries(constructor, mode, options):
193-
df = nw.from_native(constructor(px.data.stocks().to_dict(orient="list")))
192+
def test_trendline_on_timeseries(backend, mode, options):
193+
194+
df = nw.from_native(px.data.stocks(return_type=backend))
194195

195196
pd_err_msg = r"Could not convert value of 'x' \('date'\) into a numeric type."
196197
pl_err_msg = "conversion from `str` to `f64` failed in column 'date'"

0 commit comments

Comments
 (0)