Skip to content

Commit c56cb91

Browse files
committed
fix: avoid single-element comparator-sets
known [issue](pandas-dev/pandas#16864) in Pandas.
1 parent 2fb48b7 commit c56cb91

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

data-pipeline/src/pipeline/comparator_sets.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,15 @@ def compute_distances(
417417
distances=pupil_distances[idx],
418418
include=include_pupils,
419419
)
420-
pupils.loc[urn] = top_pupil_set_urns
420+
# note: single-element arrays are unpacked; in this
421+
# case, do not produce a comparator-set.
422+
if len(top_pupil_set_urns) == 1:
423+
logger.warning(
424+
f"Unable to produce pupil comparator-set for URN: {urn}."
425+
)
426+
pupils.loc[urn] = np.array([])
427+
else:
428+
pupils.loc[urn] = top_pupil_set_urns
421429

422430
if not row["_GenerateBuildingComparatorSet"][idx]:
423431
buildings.loc[urn] = np.array([])
@@ -432,7 +440,13 @@ def compute_distances(
432440
building_distances[idx],
433441
include=include_buildings,
434442
)
435-
buildings.loc[urn] = top_building_set_urns
443+
if len(top_building_set_urns) == 1:
444+
logger.warning(
445+
f"Unable to produce building comparator-set for URN: {urn}."
446+
)
447+
buildings.loc[urn] = np.array([])
448+
else:
449+
buildings.loc[urn] = top_building_set_urns
436450
except Exception as error:
437451
logger.exception(
438452
f"An exception occurred {type(error).__name__} processing {urn}:",

0 commit comments

Comments
 (0)