Skip to content

CLN: remove unused NDFrame methods #30935

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 4 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
64 changes: 2 additions & 62 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,6 @@ def _construct_axes_dict(self, axes=None, **kwargs):
d.update(kwargs)
return d

@staticmethod
def _construct_axes_dict_from(self, axes, **kwargs):
"""Return an axes dictionary for the passed axes."""
d = {a: ax for a, ax in zip(self._AXIS_ORDERS, axes)}
d.update(kwargs)
return d

def _construct_axes_from_arguments(
self, args, kwargs, require_all: bool = False, sentinel=None
):
Expand Down Expand Up @@ -381,18 +374,6 @@ def _construct_axes_from_arguments(
axes = {a: kwargs.pop(a, sentinel) for a in self._AXIS_ORDERS}
return axes, kwargs

@classmethod
def _from_axes(cls: Type[FrameOrSeries], data, axes, **kwargs) -> FrameOrSeries:
# for construction from BlockManager
if isinstance(data, BlockManager):
return cls(data, **kwargs)
else:
if cls._AXIS_REVERSED:
axes = axes[::-1]
d = cls._construct_axes_dict_from(cls, axes, copy=False)
d.update(kwargs)
return cls(data, **d)

@classmethod
def _get_axis_number(cls, axis):
axis = cls._AXIS_ALIASES.get(axis, axis)
Expand Down Expand Up @@ -908,23 +889,7 @@ def squeeze(self, axis=None):
]

def swaplevel(self: FrameOrSeries, i=-2, j=-1, axis=0) -> FrameOrSeries:
"""
Swap levels i and j in a MultiIndex on a particular axis

Parameters
----------
i, j : int, str (can be mixed)
Level of index to be swapped. Can pass level name as string.

Returns
-------
swapped : same type as caller (new object)
"""
axis = self._get_axis_number(axis)
result = self.copy()
labels = result._data.axes[axis]
result._data.set_axis(axis, labels.swaplevel(i, j))
return result
raise AbstractMethodError(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rationale?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it because of the additional copy parameter in Series.swaplevel that the generic method cannot retained and frame and series call super in preference to removing the generic implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be removed entirely?


# ----------------------------------------------------------------------
# Rename
Expand Down Expand Up @@ -4268,22 +4233,7 @@ def sort_index(
sorted_obj : DataFrame or None
DataFrame with sorted index if inplace=False, None otherwise.
"""
inplace = validate_bool_kwarg(inplace, "inplace")
axis = self._get_axis_number(axis)
axis_name = self._get_axis_name(axis)
labels = self._get_axis(axis)

if level is not None:
raise NotImplementedError("level is not implemented")
if inplace:
raise NotImplementedError("inplace is not implemented")

sort_index = labels.argsort()
if not ascending:
sort_index = sort_index[::-1]

new_axis = labels.take(sort_index)
return self.reindex(**{axis_name: new_axis})
raise AbstractMethodError(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rationale?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually can you just remove this entirely? its defined in both series/frame with doc-strings.


def reindex(self: FrameOrSeries, *args, **kwargs) -> FrameOrSeries:
"""
Expand Down Expand Up @@ -5367,11 +5317,6 @@ def _is_numeric_mixed_type(self):
f = lambda: self._data.is_numeric_mixed_type
return self._protect_consolidate(f)

@property
def _is_datelike_mixed_type(self):
f = lambda: self._data.is_datelike_mixed_type
return self._protect_consolidate(f)

def _check_inplace_setting(self, value) -> bool_t:
""" check whether we allow in-place setting with this type of value """

Expand Down Expand Up @@ -5480,11 +5425,6 @@ def _values(self) -> np.ndarray:
"""internal implementation"""
return self.values

@property
def _get_values(self) -> np.ndarray:
# compat
return self.values

def _internal_get_values(self) -> np.ndarray:
"""
Return an ndarray after converting sparse values to dense.
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,7 @@ def get_result(self):
new_data._consolidate_inplace()

cons = self.objs[0]._constructor
return cons._from_axes(new_data, self.new_axes).__finalize__(
self, method="concat"
)
return cons(new_data).__finalize__(self, method="concat")

def _get_result_dim(self) -> int:
if self._is_series and self.axis == 1:
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,6 @@ def test_validate_bool_args(self):
with pytest.raises(ValueError):
super(DataFrame, df).drop("a", axis=1, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).sort_index(inplace=value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being dropped?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this would technically raise an AbstractMethodError now; indifferent on whether should update the error or keep removed

But would be nice to update this test for Python3 super calls and parametrization

with pytest.raises(ValueError):
super(DataFrame, df)._consolidate(inplace=value)

Expand Down