Skip to content

ENH: to_list as alias for tolist #23398

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 8 commits into from
Dec 13, 2018
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
Next Next commit
Added test, added tolist to _dir_deletions, changed whatsnew and api.rst
  • Loading branch information
retkowski committed Dec 10, 2018
commit ab070fa15a4494881c35235f511ee904811ec45a
2 changes: 2 additions & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ Conversion
Series.to_period
Series.to_timestamp
Series.tolist
Series.to_list
Series.get_values


Expand Down Expand Up @@ -1535,6 +1536,7 @@ Conversion
Index.map
Index.ravel
Index.tolist
Index.to_list
Index.to_native_types
Index.to_series
Index.to_frame
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ Other API Changes
- The order of the arguments of :func:`DataFrame.to_html` and :func:`DataFrame.to_string` is rearranged to be consistent with each other. (:issue:`23614`)
- :meth:`CategoricalIndex.reindex` now raises a ``ValueError`` if the target index is non-unique and not equal to the current index. It previously only raised if the target index was not of a categorical dtype (:issue:`23963`).
- ``Series.tolist()`` and ``Index.tolist()`` now have an alias ``to_list`` (:issue:`8826`)
- :func:`Series.tolist` and :func:`Index.tolist()` now have an alias ``to_list`` (:issue:`8826`)

.. _whatsnew_0240.deprecations:

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Categorical(ExtensionArray, PandasObject):
# ops, which raise
__array_priority__ = 1000
_dtype = CategoricalDtype(ordered=False)
_deprecations = frozenset(['labels'])
_deprecations = frozenset(['labels', 'tolist'])
_typ = 'categorical'

def __init__(self, values, categories=None, ordered=None, dtype=None,
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from pandas.core.ops import get_op_result_name, make_invalid_op
import pandas.core.sorting as sorting
from pandas.core.strings import StringMethods
from pandas.core.accessor import DirNamesMixin

from pandas.io.formats.printing import (
default_pprint, format_object_attrs, format_object_summary, pprint_thing)
Expand Down Expand Up @@ -202,6 +203,8 @@ class Index(IndexOpsMixin, PandasObject):
>>> pd.Index(list('abc'))
Index(['a', 'b', 'c'], dtype='object')
"""
_deprecations = DirNamesMixin._deprecations | frozenset(['tolist'])

# To hand over control to subclasses
_join_precedence = 1

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
_accessors = {'dt', 'cat', 'str', 'sparse'}
_deprecations = generic.NDFrame._deprecations | frozenset(
['asobject', 'reshape', 'get_value', 'set_value',
'from_csv', 'valid'])
'from_csv', 'valid', 'tolist'])

# Override cache_readonly bc Series is mutable
hasnans = property(base.IndexOpsMixin.hasnans.func,
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,9 +1099,10 @@ class TestToIterable(object):
'method',
[
lambda x: x.tolist(),
lambda x: x.to_list(),
lambda x: list(x),
lambda x: list(x.__iter__()),
], ids=['tolist', 'list', 'iter'])
], ids=['tolist', 'to_list', 'list', 'iter'])
@pytest.mark.parametrize('typ', [Series, Index])
def test_iterable(self, typ, method, dtype, rdtype):
# gh-10904
Expand Down