PERF: copy cached attributes on index shallow_copy by topper-123 · Pull Request #32568 · pandas-dev/pandas (original) (raw)
If the _cache
has been populated before the call to _shallow_copy
, we always copy. It it hasn't, it's a question of evaluating trade-offs:
- If we access
_engine
before copying, we risk calculating unneccesarily - If we do not access it before copying, we risk having to do the same calculation several times.
My hunch is that it's mostly not that important, because either the cache has already been populated, or the original index will not be used again (e.g. in a pipe, often).
But in some given cases we'd prefer either 1 or 2, depending on context, but we'd have to choose. I prefer 2., because in that case _shallo_copy
will never halt to create new _engine
attributes, i.e. performance will be more predictable.