| 334 | |
| 335 | |
| 336 | def assign(df, *pairs): |
| 337 | # Only deep copy when updating an element |
| 338 | # (to avoid modifying the original) |
| 339 | # Setitem never modifies an array inplace with pandas 1.4 and up |
| 340 | pairs = dict(partition(2, pairs)) |
| 341 | df = df.copy(deep=False) |
| 342 | with warnings.catch_warnings(): |
| 343 | warnings.filterwarnings( |
| 344 | "ignore", |
| 345 | message="DataFrame is highly fragmented *", |
| 346 | category=PerformanceWarning, |
| 347 | ) |
| 348 | for name, val in pairs.items(): |
| 349 | df[name] = val |
| 350 | return df |
| 351 | |
| 352 | |
| 353 | def unique(x, series_name=None): |