From 392c4c23b31a3badf200d1d41c74fb5ba038b79b Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Sun, 28 Oct 2018 14:24:03 +0100 Subject: [PATCH 1/8] to_list as alias for tolist --- doc/source/whatsnew/v0.24.0.rst | 1 + pandas/core/arrays/categorical.py | 2 ++ pandas/core/base.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index a18c26f911f1d..baeb3c0b3a536 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1071,6 +1071,7 @@ Other API Changes - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). - 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`) .. _whatsnew_0240.deprecations: diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index abadd64b441b4..820b7825af765 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -567,6 +567,8 @@ def tolist(self): """ return list(self) + to_list = tolist + @property def base(self): """ diff --git a/pandas/core/base.py b/pandas/core/base.py index 1d2a0a2544dbc..47ba56eefc8e7 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1025,6 +1025,8 @@ def tolist(self): else: return self._values.tolist() + to_list = tolist + def __iter__(self): """ Return an iterator of the values. From ab070fa15a4494881c35235f511ee904811ec45a Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Sun, 28 Oct 2018 17:34:49 +0100 Subject: [PATCH 2/8] Added test, added tolist to _dir_deletions, changed whatsnew and api.rst --- doc/source/api.rst | 2 ++ doc/source/whatsnew/v0.24.0.rst | 1 + pandas/core/arrays/categorical.py | 2 +- pandas/core/indexes/base.py | 3 +++ pandas/core/series.py | 2 +- pandas/tests/test_base.py | 3 ++- 6 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/source/api.rst b/doc/source/api.rst index 49c89a53e7b17..020371bd41233 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -324,6 +324,7 @@ Conversion Series.to_period Series.to_timestamp Series.tolist + Series.to_list Series.get_values @@ -1535,6 +1536,7 @@ Conversion Index.map Index.ravel Index.tolist + Index.to_list Index.to_native_types Index.to_series Index.to_frame diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index baeb3c0b3a536..a2d088ca3a888 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -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: diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 820b7825af765..714d6b4c13aab 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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, diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fc5f6758f9e06..407111ee07b9d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -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) @@ -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 diff --git a/pandas/core/series.py b/pandas/core/series.py index 4f9465354a47b..a29263c23175a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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, diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 47fafe2a900b4..46f0f5dc97243 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -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 From 5e874544126fada9b3bddc84d0dc384a7b77e974 Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Tue, 30 Oct 2018 14:45:35 +0100 Subject: [PATCH 3/8] Removed .tolist from api.rst --- doc/source/api.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/api.rst b/doc/source/api.rst index 020371bd41233..9586483d44bdf 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -323,7 +323,6 @@ Conversion Series.bool Series.to_period Series.to_timestamp - Series.tolist Series.to_list Series.get_values @@ -1535,7 +1534,6 @@ Conversion Index.item Index.map Index.ravel - Index.tolist Index.to_list Index.to_native_types Index.to_series From f3285fd5d9841c5891928a7680f2c3fed43bc892 Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Tue, 30 Oct 2018 14:49:34 +0100 Subject: [PATCH 4/8] Added to_list test for categories --- pandas/tests/test_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 46f0f5dc97243..488032b6f4280 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -1123,9 +1123,10 @@ def test_iterable(self, typ, method, dtype, rdtype): '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_object_and_category(self, typ, method, dtype, rdtype, obj): From e6a90a22cc0f50751f398ff33980bcadf345f0f3 Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Wed, 31 Oct 2018 15:03:13 +0100 Subject: [PATCH 5/8] Added 'not deprecated' note --- pandas/core/arrays/categorical.py | 1 + pandas/core/indexes/base.py | 1 + pandas/core/series.py | 1 + pandas/tests/test_base.py | 3 ++- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 714d6b4c13aab..54929845c4b30 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -309,6 +309,7 @@ class Categorical(ExtensionArray, PandasObject): # ops, which raise __array_priority__ = 1000 _dtype = CategoricalDtype(ordered=False) + # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = frozenset(['labels', 'tolist']) _typ = 'categorical' diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 407111ee07b9d..8854798171069 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -203,6 +203,7 @@ class Index(IndexOpsMixin, PandasObject): >>> pd.Index(list('abc')) Index(['a', 'b', 'c'], dtype='object') """ + # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = DirNamesMixin._deprecations | frozenset(['tolist']) # To hand over control to subclasses diff --git a/pandas/core/series.py b/pandas/core/series.py index a29263c23175a..f9c9c3ab81937 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -134,6 +134,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): """ _metadata = ['name'] _accessors = {'dt', 'cat', 'str', 'sparse'} + # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = generic.NDFrame._deprecations | frozenset( ['asobject', 'reshape', 'get_value', 'set_value', 'from_csv', 'valid', 'tolist']) diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 488032b6f4280..9f0def034f976 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -1169,9 +1169,10 @@ def test_iterable_map(self, typ, dtype, rdtype): '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']) def test_categorial_datetimelike(self, method): i = CategoricalIndex([Timestamp('1999-12-31'), Timestamp('2000-12-31')]) From b15bfe942c35d79e31584bd9a0004087175a7e07 Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Mon, 10 Dec 2018 18:22:46 +0100 Subject: [PATCH 6/8] Updated tolist to to_list in doc examples --- doc/source/timedeltas.rst | 10 +++++----- doc/source/timeseries.rst | 6 +++--- doc/source/whatsnew/v0.24.0.rst | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/source/timedeltas.rst b/doc/source/timedeltas.rst index b32603cb78795..8c4928cd8165e 100644 --- a/doc/source/timedeltas.rst +++ b/doc/source/timedeltas.rst @@ -436,11 +436,11 @@ Finally, the combination of ``TimedeltaIndex`` with ``DatetimeIndex`` allow cert .. ipython:: python tdi = pd.TimedeltaIndex(['1 days', pd.NaT, '2 days']) - tdi.tolist() + tdi.to_list() dti = pd.date_range('20130101', periods=3) - dti.tolist() - (dti + tdi).tolist() - (dti - tdi).tolist() + dti.to_list() + (dti + tdi).to_list() + (dti - tdi).to_list() Conversions ~~~~~~~~~~~ @@ -461,7 +461,7 @@ Scalars type ops work as well. These can potentially return a *different* type o # subtraction of a date and a timedelta -> datelike # note that trying to subtract a date from a Timedelta will raise an exception - (pd.Timestamp('20130101') - tdi).tolist() + (pd.Timestamp('20130101') - tdi).to_list() # timedelta + timedelta -> timedelta tdi + pd.Timedelta('10 days') diff --git a/doc/source/timeseries.rst b/doc/source/timeseries.rst index 0d6fc735f3025..2a6249bef112b 100644 --- a/doc/source/timeseries.rst +++ b/doc/source/timeseries.rst @@ -2338,7 +2338,7 @@ Infer the ambiguous times .. ipython:: python rng_hourly_eastern = rng_hourly.tz_localize('US/Eastern', ambiguous='infer') - rng_hourly_eastern.tolist() + rng_hourly_eastern.to_list() In addition to 'infer', there are several other arguments supported. Passing an array-like of bools or 0s/1s where True represents a DST hour and False a @@ -2351,8 +2351,8 @@ constructor as well as ``tz_localize``. .. ipython:: python rng_hourly_dst = np.array([1, 1, 0, 0, 0]) - rng_hourly.tz_localize('US/Eastern', ambiguous=rng_hourly_dst).tolist() - rng_hourly.tz_localize('US/Eastern', ambiguous='NaT').tolist() + rng_hourly.tz_localize('US/Eastern', ambiguous=rng_hourly_dst).to_list() + rng_hourly.tz_localize('US/Eastern', ambiguous='NaT').to_list() didx = pd.DatetimeIndex(start='2014-08-01 09:00', freq='H', periods=10, tz='US/Eastern') diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index a2d088ca3a888..f01d4edfbf92d 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1071,7 +1071,6 @@ Other API Changes - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). - 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: From 6d1803b358294da27d054d651e40d55185c68c48 Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Tue, 11 Dec 2018 01:19:32 +0100 Subject: [PATCH 7/8] Fixing Import Order --- pandas/core/indexes/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 8854798171069..3d037af26b954 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -31,7 +31,7 @@ from pandas.core.dtypes.missing import array_equivalent, isna from pandas.core import ops -from pandas.core.accessor import CachedAccessor +from pandas.core.accessor import CachedAccessor, DirNamesMixin import pandas.core.algorithms as algos from pandas.core.arrays import ExtensionArray from pandas.core.base import IndexOpsMixin, PandasObject @@ -41,7 +41,6 @@ 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) From c57e8eb08e472431d24339919a64514911a798b5 Mon Sep 17 00:00:00 2001 From: ScientiaEtVeritas Date: Wed, 12 Dec 2018 18:04:29 +0100 Subject: [PATCH 8/8] Fixing whatsnew entry --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index f01d4edfbf92d..8a7f6f3f707e1 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1071,7 +1071,7 @@ Other API Changes - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). - 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`). -- :func:`Series.tolist` and :func:`Index.tolist()` now have an alias ``to_list`` (:issue:`8826`) +- :func:`Series.to_list` and :func:`Index.to_list` are now aliases of ``Series.tolist`` respectively ``Index.tolist`` (:issue:`8826`) .. _whatsnew_0240.deprecations: