Improve coverage of NDFrame.__finalize__
Pandas uses NDFrame.__finalize__
to propagate metadata from one NDFrame to
another. This ensures that things like self.attrs
and self.flags
are not
lost. In general we would like that any operation that accepts one or more
NDFrames and returns an NDFrame should propagate metadata by calling__finalize__
.
The test file at
https://github.com/pandas-dev/pandas/blob/master/pandas/tests/generic/test_finalize.py
attempts to be an exhaustive suite of tests for all these cases. However there
are many tests currently xfailing, and there are likely many APIs not covered.
This is a meta-issue to improve the use of __finalize__
. Here's a hopefully
accurate list of methods that don't currently call finalize.
Some general comments around finalize
attrs
when there are__finalize__
can be somewhat expensiveDataFrame.apply
which is sometimes used internally. We may needDataFrame.apply
that calls an internalDataFrame._apply
. The internal method would not call __finalize__
, just theDataFrame.apply
would.If you're interested in working on this please post a comment indicating which method
you're working on. Un-xfail the test, then update the method to pass the test. Some of these
will be much more difficult to work on than others (e.g. groupby is going to be difficult). If you're
unsure whether a particular method is likely to be difficult, ask first.
DataFrame.__getitem__
with a scalarDataFrame.eval
with engine="numexpr"
DataFrame.duplicated
DataFrame.add
, mul
, etc. (at least for most things; some work to do on conflicts / overlapping attrs in binops)DataFrame.combine
, DataFrame.combine_first
DataFrame.update
DataFrame.pivot
, pivot_table
DataFrame.stack
DataFrame.unstack
DataFrame.explode
BUG: added finalize to explode, GH28283 #46629DataFrame.melt
BUG/TST/DOC: added finalize to melt, GH28283 #46648DataFrame.diff
DataFrame.applymap
DataFrame.append
DataFrame.merge
DataFrame.cov
DataFrame.corrwith
DataFrame.count
DataFrame.nunique
DataFrame.idxmax
, idxmin
DataFrame.mode
DataFrame.quantile
(scalar and list of quantiles)DataFrame.isin
DataFrame.pop
DataFrame.squeeze
Series.abs
DataFrame.get
DataFrame.round
DataFrame.convert_dtypes
DataFrame.pct_change
DataFrame.transform
DataFrame.apply
DataFrame.any
, sum
, std
, mean
, etdc.Series.str.
operations returning a Series / DataFrameSeries.dt.
operations returning a Series / DataFrameSeries.cat.
operations returning a Series / DataFrame.iloc
/ .loc
Add missing __finalize__ calls in indexers/iterators #46101riyadparvez, peterpanmj, basnijholt and zhuxy-astro
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4