| 2314 | """ |
| 2315 | |
| 2316 | def add( # type: ignore[override] |
| 2317 | self, |
| 2318 | column: _NAMEDCOL, |
| 2319 | key: Optional[str] = None, |
| 2320 | *, |
| 2321 | index: Optional[int] = None, |
| 2322 | ) -> None: |
| 2323 | if key is not None and column.key != key: |
| 2324 | raise exc.ArgumentError( |
| 2325 | "DedupeColumnCollection requires columns be under " |
| 2326 | "the same key as their .key" |
| 2327 | ) |
| 2328 | key = column.key |
| 2329 | |
| 2330 | if key is None: |
| 2331 | raise exc.ArgumentError( |
| 2332 | "Can't add unnamed column to column collection" |
| 2333 | ) |
| 2334 | |
| 2335 | if key in self._index: |
| 2336 | existing = self._index[key][1] |
| 2337 | |
| 2338 | if existing is column: |
| 2339 | return |
| 2340 | |
| 2341 | self.replace(column, index=index) |
| 2342 | |
| 2343 | # pop out memoized proxy_set as this |
| 2344 | # operation may very well be occurring |
| 2345 | # in a _make_proxy operation |
| 2346 | util.memoized_property.reset(column, "proxy_set") |
| 2347 | else: |
| 2348 | self._append_new_column(key, column, index=index) |
| 2349 | |
| 2350 | def _append_new_column( |
| 2351 | self, key: str, named_column: _NAMEDCOL, *, index: Optional[int] = None |