Skip to content

Commit 48c7f62

Browse files
committed
defensive from_native call
1 parent 2630a5a commit 48c7f62

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

packages/python/plotly/_plotly_utils/basevalidators.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ def copy_to_readonly_numpy_array(v, kind=None, force_numeric=False):
7373
"""
7474
np = get_module("numpy")
7575

76-
# Don't force pandas to be loaded, we only want to know if it's already loaded
77-
pd = get_module("pandas", should_load=False)
7876
assert np is not None
7977

8078
# ### Process kind ###
@@ -94,6 +92,10 @@ def copy_to_readonly_numpy_array(v, kind=None, force_numeric=False):
9492
"O": "object",
9593
}
9694

95+
# With `pass_through=True``, the original object will be returned if unable to convert
96+
# to a Narwhals DataFrame or Series.
97+
v = nw.from_native(v, allow_series=True, pass_through=True)
98+
9799
if isinstance(v, nw.Series):
98100
if v.dtype == nw.Datetime and v.dtype.time_zone is not None:
99101
# Remove time zone so that local time is displayed

packages/python/plotly/plotly/express/_core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ def to_unindexed_series(x, name=None, native_namespace=None):
11741174
its index reset if pandas-like). Stripping the index from existing pd.Series is
11751175
required to get things to match up right in the new DataFrame we're building.
11761176
"""
1177-
x = nw.from_native(x, series_only=True, strict=False)
1177+
x = nw.from_native(x, series_only=True, pass_through=True)
11781178
if isinstance(x, nw.Series):
11791179
return nw.maybe_reset_index(x).rename(name)
11801180
elif native_namespace is not None:
@@ -1380,7 +1380,7 @@ def process_args_into_dataframe(
13801380
)
13811381

13821382
df_output[str(col_name)] = to_unindexed_series(
1383-
x=nw.from_native(argument, series_only=True, strict=False),
1383+
x=nw.from_native(argument, series_only=True, pass_through=True),
13841384
name=str(col_name),
13851385
native_namespace=native_namespace,
13861386
)
@@ -1508,11 +1508,11 @@ def build_dataframe(args, constructor):
15081508
is_pd_like = True
15091509

15101510
# data_frame is any other DataFrame object natively supported via Narwhals.
1511-
# With strict=False, the original object will be returned if unable to convert
1511+
# With pass_through=True, the original object will be returned if unable to convert
15121512
# to a Narwhals DataFrame, making this condition False.
15131513
elif isinstance(
15141514
data_frame := nw.from_native(
1515-
args["data_frame"], eager_or_interchange_only=True, strict=False
1515+
args["data_frame"], eager_or_interchange_only=True, pass_through=True
15161516
),
15171517
nw.DataFrame,
15181518
):
@@ -1521,11 +1521,11 @@ def build_dataframe(args, constructor):
15211521
columns = args["data_frame"].columns
15221522

15231523
# data_frame is any other Series object natively supported via Narwhals.
1524-
# With strict=False, the original object will be returned if unable to convert
1524+
# With pass_through=True, the original object will be returned if unable to convert
15251525
# to a Narwhals DataFrame, making this condition False.
15261526
elif isinstance(
15271527
series := nw.from_native(
1528-
args["data_frame"], series_only=True, strict=False
1528+
args["data_frame"], series_only=True, pass_through=True
15291529
),
15301530
nw.Series,
15311531
):

packages/python/plotly/plotly/express/_imshow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def imshow(
321321
aspect = "equal"
322322

323323
# --- Set the value of binary_string (forbidden for pandas)
324-
img = nw.from_native(img, strict=False)
324+
img = nw.from_native(img, pass_through=True)
325325
if isinstance(img, nw.DataFrame):
326326
if binary_string:
327327
raise ValueError("Binary strings cannot be used with pandas arrays")

0 commit comments

Comments
 (0)