Skip to content

Fixed Metadata Propogation in DataFrame #37381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 4, 2020
14 changes: 7 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,7 @@ def eval(self, expr, inplace=False, **kwargs):
kwargs["target"] = self
kwargs["resolvers"] = kwargs.get("resolvers", ()) + tuple(resolvers)

return _eval(expr, inplace=inplace, **kwargs)
return _eval(expr, inplace=inplace, **kwargs).__finalize__(self,"eval")

def select_dtypes(self, include=None, exclude=None) -> DataFrame:
"""
Expand Down Expand Up @@ -6488,7 +6488,7 @@ def update(
continue

self[col] = expressions.where(mask, this, that)

self.__finalize__(self,"update")
# ----------------------------------------------------------------------
# Data reshaping
@Appender(
Expand Down Expand Up @@ -7351,7 +7351,7 @@ def diff(self, periods: int = 1, axis: Axis = 0) -> DataFrame:
return self - self.shift(periods, axis=axis)

new_data = self._mgr.diff(n=periods, axis=bm_axis)
return self._constructor(new_data)
return self._constructor(new_data).__finalize__(self,"diff")

# ----------------------------------------------------------------------
# Function application
Expand Down Expand Up @@ -7730,7 +7730,7 @@ def infer(x):
return lib.map_infer(x, func, ignore_na=ignore_na)
return lib.map_infer(x.astype(object)._values, func, ignore_na=ignore_na)

return self.apply(infer)
return self.apply(infer).__finalize__(self,"applymap")

# ----------------------------------------------------------------------
# Merging / joining methods
Expand Down Expand Up @@ -7867,12 +7867,12 @@ def append(
to_concat = [self, *other]
else:
to_concat = [self, other]
return concat(
return (concat(
to_concat,
ignore_index=ignore_index,
verify_integrity=verify_integrity,
sort=sort,
)
)).__finalize__(self, method="append")

def join(
self, other, on=None, how="left", lsuffix="", rsuffix="", sort=False
Expand Down Expand Up @@ -8084,7 +8084,7 @@ def merge(
copy=copy,
indicator=indicator,
validate=validate,
)
).__finalize__(self,method="merge")

def round(self, decimals=0, *args, **kwargs) -> DataFrame:
"""
Expand Down
19 changes: 6 additions & 13 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@
(pd.DataFrame, ({("A", "a"): [1]},), operator.methodcaller("__getitem__", ["A"])),
(pd.DataFrame, frame_data, operator.methodcaller("query", "A == 1")),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("eval", "A + 1")),
marks=not_implemented_mark,
(pd.DataFrame, frame_data, operator.methodcaller("eval", "A + 1"))
),
(pd.DataFrame, frame_data, operator.methodcaller("select_dtypes", include="int")),
(pd.DataFrame, frame_data, operator.methodcaller("assign", b=1)),
Expand Down Expand Up @@ -155,7 +154,6 @@
frame_data,
operator.methodcaller("update", pd.DataFrame(*frame_data)),
),
marks=not_implemented_mark,
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("pivot", columns="A")),
Expand Down Expand Up @@ -190,36 +188,31 @@
marks=not_implemented_mark,
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("diff")),
marks=not_implemented_mark,
),
(pd.DataFrame, frame_data, operator.methodcaller("diff"))
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("applymap", lambda x: x)),
marks=not_implemented_mark,
(pd.DataFrame, frame_data, operator.methodcaller("applymap", lambda x: x))
),
pytest.param(
(
pd.DataFrame,
frame_data,
operator.methodcaller("append", pd.DataFrame({"A": [1]})),
),
marks=not_implemented_mark,
)
),
pytest.param(
(
pd.DataFrame,
frame_data,
operator.methodcaller("append", pd.DataFrame({"B": [1]})),
),
marks=not_implemented_mark,
),
pytest.param(
(
pd.DataFrame,
frame_data,
operator.methodcaller("merge", pd.DataFrame({"A": [1]})),
),
marks=not_implemented_mark,
)
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("round", 2)),
Expand Down