From f07a4071e6ecdf3ac4621616bb8623559e4caa5f Mon Sep 17 00:00:00 2001 From: TomAugspurger Date: Tue, 22 Apr 2014 12:55:17 -0500 Subject: [PATCH] Deprecate order kwarg in factorize --- doc/source/release.rst | 2 ++ doc/source/v0.14.0.txt | 1 + pandas/core/algorithms.py | 7 ++++++- pandas/tests/test_algos.py | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index e38d5e00a31ad..0ad7793285000 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -206,6 +206,8 @@ Deprecations ``periods`` with a default value of 1. A ``FutureWarning`` is raised if the old argument ``lags`` is used by name. (:issue:`6910`) +- The ``order`` keyword argument of :func:`factorize` will be removed. (:issue:`6926`). + Prior Version Deprecations/Changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/source/v0.14.0.txt b/doc/source/v0.14.0.txt index b3ee1fdef30a8..242c27ebbf9b0 100644 --- a/doc/source/v0.14.0.txt +++ b/doc/source/v0.14.0.txt @@ -420,6 +420,7 @@ Deprecations The old positional argument ``lags`` has been changed to a keyword argument ``periods`` with a default value of 1. A ``FutureWarning`` is raised if the old argument ``lags`` is used by name. (:issue:`6910`) +- The ``order`` keyword argument of :func:`factorize` will be removed. (:issue:`6926`). .. _whatsnew_0140.enhancements: diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index e2ef178c62e71..5efba4a9738af 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -11,6 +11,7 @@ import pandas.hashtable as htable import pandas.compat as compat from pandas.compat import filter, string_types +from pandas.util.decorators import deprecate_kwarg def match(to_match, values, na_sentinel=-1): """ @@ -104,7 +105,7 @@ def factorize(values, sort=False, order=None, na_sentinel=-1): Sequence sort : boolean, default False Sort by values - order : + order : deprecated na_sentinel: int, default -1 Value to mark "not found" @@ -115,6 +116,10 @@ def factorize(values, sort=False, order=None, na_sentinel=-1): note: an array of Periods will ignore sort as it returns an always sorted PeriodIndex """ + if order is not None: + warn("order is deprecated." + "See https://github.com/pydata/pandas/issues/6926", FutureWarning) + from pandas.tseries.period import PeriodIndex vals = np.asarray(values) is_datetime = com.is_datetime64_dtype(vals) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index ebc41ea457b52..07bf247e5aafe 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -47,6 +47,12 @@ def test_strings(self): class TestFactorize(tm.TestCase): _multiprocess_can_split_ = True + def test_warn(self): + + s = Series([1, 2, 3]) + with tm.assert_produces_warning(FutureWarning): + algos.factorize(s, order='A') + def test_basic(self): labels, uniques = algos.factorize(['a', 'b', 'b', 'a',