Skip to content
Open
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
Prev Previous commit
Next Next commit
Address code review feedback: improve None handling and add title tru…
…ncation logic

Co-authored-by: jnumainville <10480451+jnumainville@users.noreply.github.com>
  • Loading branch information
Copilot and jnumainville committed Nov 7, 2025
commit 287266fb99c6822a7e1ea965aa1ca168677bf1bd
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,21 @@ def atomic_make_subplots(
final_subplot_titles.append("")
else:
extracted_title = extract_title_from_figure(fig)
# Explicitly check for None to handle empty strings correctly
final_subplot_titles.append(
extracted_title if extracted_title else ""
extracted_title if extracted_title is not None else ""
)
elif subplot_titles is not None:
# Convert to list if tuple
final_subplot_titles = list(subplot_titles)

# Pad with empty strings if needed
# Validate and adjust length if needed
total_subplots = rows * cols
if len(final_subplot_titles) < total_subplots:
if len(final_subplot_titles) > total_subplots:
# Truncate if too many titles provided
final_subplot_titles = final_subplot_titles[:total_subplots]
elif len(final_subplot_titles) < total_subplots:
# Pad with empty strings if too few titles provided
final_subplot_titles.extend(
[""] * (total_subplots - len(final_subplot_titles))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ def test_make_subplots_conflicting_title_options(self):

self.assertIn("Cannot use both", str(context.exception))

def test_make_subplots_with_too_many_subplot_titles(self):
import src.deephaven.plot.express as dx

chart = dx.scatter(self.source, x="X", y="Y")
# Provide more titles than subplots - should be truncated
charts = dx.make_subplots(
chart,
chart,
rows=2,
subplot_titles=["Plot 1", "Plot 2", "Plot 3", "Plot 4"],
).to_dict(self.exporter)

# Check that only 2 annotations were created (truncated)
layout = charts["plotly"]["layout"]
self.assertIn("annotations", layout)
annotations = layout["annotations"]
self.assertEqual(len(annotations), 2)
self.assertEqual(annotations[0]["text"], "Plot 1")
self.assertEqual(annotations[1]["text"], "Plot 2")


if __name__ == "__main__":
unittest.main()