def _upstream_HB_basins(hybas_id, HB_gdf):
    """
    Finds all the HB basins draining into the one specified by hybas_id.
    """
    visited_subbasins = set([hybas_id])
    to_visit = set([hybas_id])
    while to_visit:
        this_basin = to_visit.pop()
        to_visit.update(
            set(HB_gdf[HB_gdf["NEXT_DOWN"] == this_basin]["HYBAS_ID"].values.tolist())
        )
        visited_subbasins.update(to_visit)
    HB_upstream = HB_gdf[HB_gdf["HYBAS_ID"].isin(visited_subbasins)]

    return HB_upstream