From cf4cebe6d3eb71ae53456f692aa10cadacfebc15 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 8 Apr 2021 11:58:51 +0200 Subject: [PATCH] Ensure GridSpec override handles duplicate matches --- panel/layout/grid.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/panel/layout/grid.py b/panel/layout/grid.py index cbe561e0a0..b34e267d40 100644 --- a/panel/layout/grid.py +++ b/panel/layout/grid.py @@ -437,9 +437,9 @@ def __setitem__(self, index, obj): grid = clone.grid grid[t:b, l:r] += 1 - overlap_grid = grid>1 + overlap_grid = grid > 1 new_objects = OrderedDict(self.objects) - if (overlap_grid).any(): + if overlap_grid.any(): overlapping = '' objects = [] for (yidx, xidx) in zip(*np.where(overlap_grid)): @@ -465,7 +465,10 @@ def __setitem__(self, index, obj): objects = [list(subgrid)[0][0]] if subgrid else [] else: objects = [list(o)[0][0] for o in subgrid.flatten()] - for dkey in objects: - del new_objects[dkey] + for dkey in set(objects): + try: + del new_objects[dkey] + except KeyError: + continue new_objects[key] = panel(obj) self.objects = new_objects