88from packaging import version
99import unittest .mock as mock
1010from plotly .express ._core import build_dataframe
11+ from plotly import optional_imports
1112from pandas .testing import assert_frame_equal
1213import sys
1314import warnings
1415
1516
17+ # FIXME: don't test with vaex if vaex isn't installed
18+ if (optional_imports .get_module ("vaex" ) is None ) and (sys .version_info >= (3 , 12 )):
19+ TEST_LIBS = ["polars" ]
20+ else :
21+ TEST_LIBS = ["vaex" , "polars" ]
22+
23+
1624def test_numpy ():
1725 fig = px .scatter (x = [1 , 2 , 3 ], y = [2 , 3 , 4 ], color = [1 , 3 , 9 ])
1826 assert np .all (fig .data [0 ].x == np .array ([1 , 2 , 3 ]))
@@ -342,7 +350,7 @@ def __dataframe__(self, allow_copy: bool = True):
342350 or sys .version_info >= (3 , 12 ),
343351 reason = "plotly doesn't use a dataframe interchange protocol for pandas < 2.0.2" ,
344352)
345- @pytest .mark .parametrize ("test_lib" , [ "vaex" , "polars" ] )
353+ @pytest .mark .parametrize ("test_lib" , TEST_LIBS )
346354def test_build_df_from_vaex_and_polars (test_lib ):
347355 if test_lib == "vaex" :
348356 import vaex as lib
@@ -365,7 +373,7 @@ def test_build_df_from_vaex_and_polars(test_lib):
365373 or sys .version_info >= (3 , 12 ),
366374 reason = "plotly doesn't use a dataframe interchange protocol for pandas < 2.0.2" ,
367375)
368- @pytest .mark .parametrize ("test_lib" , [ "vaex" , "polars" ] )
376+ @pytest .mark .parametrize ("test_lib" , TEST_LIBS )
369377@pytest .mark .parametrize (
370378 "hover_data" , [["sepal_width" ], {"sepal_length" : False , "sepal_width" : ":.2f" }]
371379)
@@ -393,7 +401,7 @@ def test_build_df_with_hover_data_from_vaex_and_polars(test_lib, hover_data):
393401
394402def test_timezones (constructor ):
395403 df = nw .from_native (
396- constructor ({"date" : ["2015-04-04 19:31:30+01:00 " ], "value" : [3 ]})
404+ constructor ({"date" : ["2015-04-04 19:31:30+0100 " ], "value" : [3 ]})
397405 ).with_columns (nw .col ("date" ).str .to_datetime (format = "%Y-%m-%d %H:%M:%S%z" ))
398406 args = dict (data_frame = df .to_native (), x = "date" , y = "value" )
399407 out = build_dataframe (args , go .Scatter )
0 commit comments