Skip to content

Pass method in __finalize__ #33273

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 6 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove underscored
  • Loading branch information
TomAugspurger committed Apr 6, 2020
commit fc74c767df38567507a9c1debda6ecaceaf3efb1
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,7 @@ def _getitem_multilevel(self, key):
result = self._constructor(
new_values, index=self.index, columns=result_columns
)
result = result.__finalize__(self, method="_getitem_multilevel")
result = result.__finalize__(self)

# If there is only one column being returned, and its name is
# either an empty string, or a tuple with an empty string as its
Expand Down
36 changes: 13 additions & 23 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ def _single_replace(self, to_replace, method, inplace, limit):
if values.dtype == orig_dtype and inplace:
return

result = pd.Series(values, index=self.index, dtype=self.dtype).__finalize__(
self, method="_single_replace"
)
result = pd.Series(values, index=self.index, dtype=self.dtype).__finalize__(self)

if inplace:
self._update_inplace(result)
Expand Down Expand Up @@ -3574,7 +3572,7 @@ def _slice(self: FrameOrSeries, slobj: slice, axis=0) -> FrameOrSeries:
assert isinstance(slobj, slice), type(slobj)
axis = self._get_block_manager_axis(axis)
result = self._constructor(self._mgr.get_slice(slobj, axis=axis))
result = result.__finalize__(self, method="_slice")
result = result.__finalize__(self)

# this could be a view
# but only in a single-dtyped view sliceable case
Expand Down Expand Up @@ -4509,9 +4507,7 @@ def _reindex_with_indexers(
if copy and new_data is self._mgr:
new_data = new_data.copy()

return self._constructor(new_data).__finalize__(
self, method="_reindex_with_indexers"
)
return self._constructor(new_data).__finalize__(self)

def filter(
self: FrameOrSeries,
Expand Down Expand Up @@ -5277,9 +5273,7 @@ def _consolidate(self, inplace: bool_t = False):
else:
f = lambda: self._mgr.consolidate()
cons_data = self._protect_consolidate(f)
return self._constructor(cons_data).__finalize__(
self, method="_consolidate"
)
return self._constructor(cons_data).__finalize__(self)

@property
def _is_mixed_type(self) -> bool_t:
Expand Down Expand Up @@ -5308,14 +5302,10 @@ def _check_inplace_setting(self, value) -> bool_t:
return True

def _get_numeric_data(self):
return self._constructor(self._mgr.get_numeric_data()).__finalize__(
self, method="_get_numeric_data"
)
return self._constructor(self._mgr.get_numeric_data()).__finalize__(self,)

def _get_bool_data(self):
return self._constructor(self._mgr.get_bool_data()).__finalize__(
self, method="_get_bool_data"
)
return self._constructor(self._mgr.get_bool_data()).__finalize__(self,)

# ----------------------------------------------------------------------
# Internal Interface Methods
Expand Down Expand Up @@ -5442,7 +5432,7 @@ def _to_dict_of_blocks(self, copy: bool_t = True):
Internal ONLY
"""
return {
k: self._constructor(v).__finalize__(self, method="_to_dict_of_blocks")
k: self._constructor(v).__finalize__(self)
for k, v, in self._mgr.to_dict(copy=copy).items()
}

Expand Down Expand Up @@ -5755,7 +5745,7 @@ def _convert(
coerce=coerce,
copy=copy,
)
).__finalize__(self, method="_convert")
).__finalize__(self)

def infer_objects(self: FrameOrSeries) -> FrameOrSeries:
"""
Expand Down Expand Up @@ -8455,8 +8445,8 @@ def _align_frame(
right.index = join_index

return (
left.__finalize__(self, method="_align_frame"),
right.__finalize__(other, method="_align_frame"),
left.__finalize__(self),
right.__finalize__(other),
)

def _align_series(
Expand Down Expand Up @@ -8542,8 +8532,8 @@ def _align_series(
right.index = join_index

return (
left.__finalize__(self, method="_align_series"),
right.__finalize__(other, method="_align_series"),
left.__finalize__(self),
right.__finalize__(other),
)

def _where(
Expand Down Expand Up @@ -8685,7 +8675,7 @@ def _where(
axis=block_axis,
)
result = self._constructor(new_data)
return result.__finalize__(self, method="_where")
return result.__finalize__(self)

_shared_docs[
"where"
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,7 @@ def _get_values_for_loc(self, series: "Series", loc, key):
new_index = self[loc]
new_index = maybe_droplevels(new_index, key)
new_ser = series._constructor(new_values, index=new_index, name=series.name)
return new_ser.__finalize__(series, method="_get_values_for_loc")
return new_ser.__finalize__(series)

def _convert_listlike_indexer(self, keyarr):
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _construct_result(
# We do not pass dtype to ensure that the Series constructor
# does inference in the case where `result` has object-dtype.
out = left._constructor(result, index=index)
out = out.__finalize__(left, method="_construct_result")
out = out.__finalize__(left)

# Set the result's name after __finalize__ is called because __finalize__
# would set it back to self.name
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,12 @@ def _get_values_tuple(self, key):
# If key is contained, would have returned by now
indexer, new_index = self.index.get_loc_level(key)
return self._constructor(self._values[indexer], index=new_index).__finalize__(
self, method="_get_values_tuple",
self,
)

def _get_values(self, indexer):
try:
return self._constructor(self._mgr.get_slice(indexer)).__finalize__(
self, method="_get_values"
)
return self._constructor(self._mgr.get_slice(indexer)).__finalize__(self,)
except ValueError:
# mpl compat if we look up e.g. ser[:, np.newaxis];
# see tests.series.timeseries.test_mpl_compat_hack
Expand Down