Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fail-fast for datasets outside the visible extent #1345

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Changes from all commits
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
23 changes: 19 additions & 4 deletions datashader/mpl_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,22 @@ def __init__(
self.plot_height = plot_height
self.width_scale = width_scale
self.height_scale = height_scale

x_col = glyph.x_label
y_col = glyph.y_label

self.bbox_df = Bbox(
np.array(
[[df[x_col].values.min(), df[y_col].values.min()],
[df[x_col].values.max(), df[y_col].values.max()]]
)
)

if x_range is None:
x_col = glyph.x_label
x_range = (df[x_col].min(), df[x_col].max())
x_range = (self.bbox_df.x0, self.bbox_df.x1)
if y_range is None:
y_col = glyph.y_label
y_range = (df[y_col].min(), df[y_col].max())
y_range = (self.bbox_df.y0, self.bbox_df.y1)

ax.set_xlim(x_range)
ax.set_ylim(y_range)

Expand Down Expand Up @@ -262,6 +272,11 @@ def make_image(self, renderer, magnification=1.0, unsampled=True):
"""
x1, x2, y1, y2 = self.get_extent()
bbox = Bbox(np.array([[x1, y1], [x2, y2]]))

# Fail-fast if visible extent does not overlap with data extent
if not bbox.overlaps(self.bbox_df):
return None, 0, 0, None

trans = self.get_transform()
transformed_bbox = TransformedBbox(bbox, trans)
if (
Expand Down
Loading