Add missing __finalize__ calls in indexers/iterators
State: closed

- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

This PR intends to add missing `__finalize__` calls to indexers and locators (this section of the docs: https://pandas.pydata.org/pandas-docs/stable/reference/frame.html#indexing-iteration). I went over all the methods listed in that section and in my opinion, everything should be covered after this PR.

This is generally in reference to #28283, although the methods covered here are not listed there. #19850 is also somewhat relevant.

The missing calls are only related to cases where a Series object was returned from indexing/iterating over a DataFrame. Though, I was somewhat generous with adding new test cases. Some newly added tests cases would have already passed before adding these calls, but I thought that it was still worth adding them.

Labels:
name: metadata
description: _metadata, .attrs

Comments:
> This broke existing tests

Should be good now. I had to un-xfail some more tests that were previously marked as not implemented.
I just need to fix the small typing validation issue if there are no other things after review.
@phofl All tests are passing now. Can you review again, please?
looks pretty good @theOehrly if you can add a release note (I think we have a few already that are about finalize so if you can group with those).
cc @phofl if you can review when you have a chance
@jreback That one failure seems unrelated? At least I'm failing to make sense of it, and it did pass previously.
Correct me if I'm wrong, though.
Looks unrelated, yes
This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.
> This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.

Still interested in working on this, not stale.

@jreback how to proceed here?
you can merge master and update to any comments
> you can merge master and update to any comments

I was waiting for a response to my comments on the review above. I guess there still are open questions that should be addressed.
can look but pls merge master
@jreback main is merged and tests are fixed again
@jreback Results of the performance benchmark for indexing (only tests that got worse):

```
Benchmarks that have got worse:

       before           after         ratio
     [0141d921]       [f75a5dd8]
                      <finalize_indexers_iterators>
+      69.2±0.8μs       85.7±0.5μs     1.24  indexing.NonNumericSeriesIndexing.time_getitem_pos_slice('string', 'nonunique_monotonic_inc')
+       477±100μs         593±80μs     1.24  indexing_engines.NumericEngineIndexing.time_get_loc((<class 'pandas._libs.index.Int16Engine'>, <class 'numpy.int16'>), 'monotonic_decr', False, 100000)
+       462±100μs         635±40μs     1.38  indexing_engines.NumericEngineIndexing.time_get_loc_near_middle((<class 'pandas._libs.index.UInt8Engine'>, <class 'numpy.uint8'>), 'monotonic_decr', False, 100000)
```

Or the full output here: https://pastebin.com/raw/3sVMufVc
@jreback any more feedback on this?
thanks @theOehrly this is very nice!