Skip to content

Commit 4ed9a39

Browse files
jbrockmendeljreback
authored andcommitted
CLN: remove unused NDFrame methods (pandas-dev#30935)
1 parent 51cb276 commit 4ed9a39

File tree

4 files changed

+41
-124
lines changed

4 files changed

+41
-124
lines changed

pandas/core/frame.py

+40-7
Original file line numberDiff line numberDiff line change
@@ -4942,19 +4942,52 @@ def sort_values(
49424942
else:
49434943
return self._constructor(new_data).__finalize__(self)
49444944

4945-
@Substitution(**_shared_doc_kwargs)
4946-
@Appender(NDFrame.sort_index.__doc__)
49474945
def sort_index(
49484946
self,
49494947
axis=0,
49504948
level=None,
4951-
ascending=True,
4952-
inplace=False,
4953-
kind="quicksort",
4954-
na_position="last",
4955-
sort_remaining=True,
4949+
ascending: bool = True,
4950+
inplace: bool = False,
4951+
kind: str = "quicksort",
4952+
na_position: str = "last",
4953+
sort_remaining: bool = True,
49564954
ignore_index: bool = False,
49574955
):
4956+
"""
4957+
Sort object by labels (along an axis).
4958+
4959+
Parameters
4960+
----------
4961+
axis : {0 or 'index', 1 or 'columns'}, default 0
4962+
The axis along which to sort. The value 0 identifies the rows,
4963+
and 1 identifies the columns.
4964+
level : int or level name or list of ints or list of level names
4965+
If not None, sort on values in specified index level(s).
4966+
ascending : bool, default True
4967+
Sort ascending vs. descending.
4968+
inplace : bool, default False
4969+
If True, perform operation in-place.
4970+
kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort'
4971+
Choice of sorting algorithm. See also ndarray.np.sort for more
4972+
information. `mergesort` is the only stable algorithm. For
4973+
DataFrames, this option is only applied when sorting on a single
4974+
column or label.
4975+
na_position : {'first', 'last'}, default 'last'
4976+
Puts NaNs at the beginning if `first`; `last` puts NaNs at the end.
4977+
Not implemented for MultiIndex.
4978+
sort_remaining : bool, default True
4979+
If True and sorting by level and index is multilevel, sort by other
4980+
levels too (in order) after sorting by specified level.
4981+
ignore_index : bool, default False
4982+
If True, the resulting axis will be labeled 0, 1, …, n - 1.
4983+
4984+
.. versionadded:: 1.0.0
4985+
4986+
Returns
4987+
-------
4988+
sorted_obj : DataFrame or None
4989+
DataFrame with sorted index if inplace=False, None otherwise.
4990+
"""
49584991

49594992
# TODO: this can be combined with Series.sort_index impl as
49604993
# almost identical

pandas/core/generic.py

-111
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,6 @@ def _construct_axes_dict(self, axes=None, **kwargs):
350350
d.update(kwargs)
351351
return d
352352

353-
@staticmethod
354-
def _construct_axes_dict_from(self, axes, **kwargs):
355-
"""Return an axes dictionary for the passed axes."""
356-
d = {a: ax for a, ax in zip(self._AXIS_ORDERS, axes)}
357-
d.update(kwargs)
358-
return d
359-
360353
def _construct_axes_from_arguments(
361354
self, args, kwargs, require_all: bool = False, sentinel=None
362355
):
@@ -385,18 +378,6 @@ def _construct_axes_from_arguments(
385378
axes = {a: kwargs.pop(a, sentinel) for a in self._AXIS_ORDERS}
386379
return axes, kwargs
387380

388-
@classmethod
389-
def _from_axes(cls: Type[FrameOrSeries], data, axes, **kwargs) -> FrameOrSeries:
390-
# for construction from BlockManager
391-
if isinstance(data, BlockManager):
392-
return cls(data, **kwargs)
393-
else:
394-
if cls._AXIS_REVERSED:
395-
axes = axes[::-1]
396-
d = cls._construct_axes_dict_from(cls, axes, copy=False)
397-
d.update(kwargs)
398-
return cls(data, **d)
399-
400381
@classmethod
401382
def _get_axis_number(cls, axis):
402383
axis = cls._AXIS_ALIASES.get(axis, axis)
@@ -911,25 +892,6 @@ def squeeze(self, axis=None):
911892
)
912893
]
913894

914-
def swaplevel(self: FrameOrSeries, i=-2, j=-1, axis=0) -> FrameOrSeries:
915-
"""
916-
Swap levels i and j in a MultiIndex on a particular axis
917-
918-
Parameters
919-
----------
920-
i, j : int, str (can be mixed)
921-
Level of index to be swapped. Can pass level name as string.
922-
923-
Returns
924-
-------
925-
swapped : same type as caller (new object)
926-
"""
927-
axis = self._get_axis_number(axis)
928-
result = self.copy()
929-
labels = result._data.axes[axis]
930-
result._data.set_axis(axis, labels.swaplevel(i, j))
931-
return result
932-
933895
# ----------------------------------------------------------------------
934896
# Rename
935897

@@ -4224,69 +4186,6 @@ def sort_values(
42244186
"""
42254187
raise AbstractMethodError(self)
42264188

4227-
def sort_index(
4228-
self,
4229-
axis=0,
4230-
level=None,
4231-
ascending: bool_t = True,
4232-
inplace: bool_t = False,
4233-
kind: str = "quicksort",
4234-
na_position: str = "last",
4235-
sort_remaining: bool_t = True,
4236-
ignore_index: bool_t = False,
4237-
):
4238-
"""
4239-
Sort object by labels (along an axis).
4240-
4241-
Parameters
4242-
----------
4243-
axis : {0 or 'index', 1 or 'columns'}, default 0
4244-
The axis along which to sort. The value 0 identifies the rows,
4245-
and 1 identifies the columns.
4246-
level : int or level name or list of ints or list of level names
4247-
If not None, sort on values in specified index level(s).
4248-
ascending : bool, default True
4249-
Sort ascending vs. descending.
4250-
inplace : bool, default False
4251-
If True, perform operation in-place.
4252-
kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort'
4253-
Choice of sorting algorithm. See also ndarray.np.sort for more
4254-
information. `mergesort` is the only stable algorithm. For
4255-
DataFrames, this option is only applied when sorting on a single
4256-
column or label.
4257-
na_position : {'first', 'last'}, default 'last'
4258-
Puts NaNs at the beginning if `first`; `last` puts NaNs at the end.
4259-
Not implemented for MultiIndex.
4260-
sort_remaining : bool, default True
4261-
If True and sorting by level and index is multilevel, sort by other
4262-
levels too (in order) after sorting by specified level.
4263-
ignore_index : bool, default False
4264-
If True, the resulting axis will be labeled 0, 1, …, n - 1.
4265-
4266-
.. versionadded:: 1.0.0
4267-
4268-
Returns
4269-
-------
4270-
sorted_obj : DataFrame or None
4271-
DataFrame with sorted index if inplace=False, None otherwise.
4272-
"""
4273-
inplace = validate_bool_kwarg(inplace, "inplace")
4274-
axis = self._get_axis_number(axis)
4275-
axis_name = self._get_axis_name(axis)
4276-
labels = self._get_axis(axis)
4277-
4278-
if level is not None:
4279-
raise NotImplementedError("level is not implemented")
4280-
if inplace:
4281-
raise NotImplementedError("inplace is not implemented")
4282-
4283-
sort_index = labels.argsort()
4284-
if not ascending:
4285-
sort_index = sort_index[::-1]
4286-
4287-
new_axis = labels.take(sort_index)
4288-
return self.reindex(**{axis_name: new_axis})
4289-
42904189
def reindex(self: FrameOrSeries, *args, **kwargs) -> FrameOrSeries:
42914190
"""
42924191
Conform %(klass)s to new index with optional filling logic.
@@ -5369,11 +5268,6 @@ def _is_numeric_mixed_type(self):
53695268
f = lambda: self._data.is_numeric_mixed_type
53705269
return self._protect_consolidate(f)
53715270

5372-
@property
5373-
def _is_datelike_mixed_type(self):
5374-
f = lambda: self._data.is_datelike_mixed_type
5375-
return self._protect_consolidate(f)
5376-
53775271
def _check_inplace_setting(self, value) -> bool_t:
53785272
""" check whether we allow in-place setting with this type of value """
53795273

@@ -5482,11 +5376,6 @@ def _values(self) -> np.ndarray:
54825376
"""internal implementation"""
54835377
return self.values
54845378

5485-
@property
5486-
def _get_values(self) -> np.ndarray:
5487-
# compat
5488-
return self.values
5489-
54905379
def _internal_get_values(self) -> np.ndarray:
54915380
"""
54925381
Return an ndarray after converting sparse values to dense.

pandas/core/reshape/concat.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ def get_result(self):
499499
new_data._consolidate_inplace()
500500

501501
cons = self.objs[0]._constructor
502-
return cons._from_axes(new_data, self.new_axes).__finalize__(
503-
self, method="concat"
504-
)
502+
return cons(new_data).__finalize__(self, method="concat")
505503

506504
def _get_result_dim(self) -> int:
507505
if self._is_series and self.axis == 1:

pandas/tests/generic/test_generic.py

-3
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,6 @@ def test_validate_bool_args(self):
548548
with pytest.raises(ValueError):
549549
super(DataFrame, df).drop("a", axis=1, inplace=value)
550550

551-
with pytest.raises(ValueError):
552-
super(DataFrame, df).sort_index(inplace=value)
553-
554551
with pytest.raises(ValueError):
555552
super(DataFrame, df)._consolidate(inplace=value)
556553

0 commit comments

Comments
 (0)