From 527ded98c3e165bdca1ef6df62ab963f8fc56f01 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 4 Mar 2017 11:32:18 +0100 Subject: [PATCH 1/2] Revert "TST: remove deprecated usages of FrozenList.__add__ from test code" This reverts commit cd677043dcfc4c6b48a6b1ad89da395a35d10e49. --- pandas/core/panel.py | 6 +++--- pandas/core/reshape.py | 6 +++--- pandas/core/strings.py | 2 +- pandas/tests/groupby/test_value_counts.py | 2 +- pandas/tools/concat.py | 2 +- test_fast.sh | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/core/panel.py b/pandas/core/panel.py index c5ea513223dce..4a6c6cf291316 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -940,9 +940,9 @@ def construct_index_parts(idx, major=True): minor_labels, minor_levels, minor_names = construct_index_parts( self.minor_axis, major=False) - levels = list(major_levels) + list(minor_levels) - labels = list(major_labels) + list(minor_labels) - names = list(major_names) + list(minor_names) + levels = major_levels + minor_levels + labels = major_labels + minor_labels + names = major_names + minor_names index = MultiIndex(levels=levels, labels=labels, names=names, verify_integrity=False) diff --git a/pandas/core/reshape.py b/pandas/core/reshape.py index faad6c500a21f..87cb088c2e91e 100644 --- a/pandas/core/reshape.py +++ b/pandas/core/reshape.py @@ -216,8 +216,8 @@ def get_new_columns(self): width = len(self.value_columns) propagator = np.repeat(np.arange(width), stride) if isinstance(self.value_columns, MultiIndex): - new_levels = self.value_columns.levels.union((self.removed_level,)) - new_names = self.value_columns.names.union((self.removed_name,)) + new_levels = self.value_columns.levels + (self.removed_level,) + new_names = self.value_columns.names + (self.removed_name,) new_labels = [lab.take(propagator) for lab in self.value_columns.labels] @@ -806,7 +806,7 @@ def melt(frame, id_vars=None, value_vars=None, var_name=None, for col in id_vars: mdata[col] = np.tile(frame.pop(col).values, K) - mcolumns = list(id_vars) + list(var_name) + list([value_name]) + mcolumns = id_vars + var_name + [value_name] mdata[value_name] = frame.values.ravel('F') for i, col in enumerate(var_name): diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 51016926d6909..ac8d1db6a0bf3 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -787,7 +787,7 @@ def str_extractall(arr, pat, flags=0): if 0 < len(index_list): from pandas import MultiIndex index = MultiIndex.from_tuples( - index_list, names=arr.index.names.union(["match"])) + index_list, names=arr.index.names + ["match"]) else: index = None result = arr._constructor_expanddim(match_list, index=index, diff --git a/pandas/tests/groupby/test_value_counts.py b/pandas/tests/groupby/test_value_counts.py index ff01df2693c7c..801d0da070112 100644 --- a/pandas/tests/groupby/test_value_counts.py +++ b/pandas/tests/groupby/test_value_counts.py @@ -28,7 +28,7 @@ def check_value_counts(df, keys, bins): gr = df.groupby(keys, sort=isort) right = gr['3rd'].apply(Series.value_counts, **kwargs) - right.index.names = right.index.names[:-1].union(['3rd']) + right.index.names = right.index.names[:-1] + ['3rd'] # have to sort on index because of unstable sort on values left, right = map(rebuild_index, (left, right)) # xref GH9212 diff --git a/pandas/tools/concat.py b/pandas/tools/concat.py index ae9d7af9d98ff..6405106118472 100644 --- a/pandas/tools/concat.py +++ b/pandas/tools/concat.py @@ -574,7 +574,7 @@ def _make_concat_multiindex(indexes, keys, levels=None, names=None): " not have the same number of levels") # also copies - names = list(names) + list(_get_consensus_names(indexes)) + names = names + _get_consensus_names(indexes) return MultiIndex(levels=levels, labels=label_list, names=names, verify_integrity=False) diff --git a/test_fast.sh b/test_fast.sh index f22ab73277e8b..30ac7f84cbe8b 100755 --- a/test_fast.sh +++ b/test_fast.sh @@ -5,4 +5,4 @@ # https://github.com/pytest-dev/pytest/issues/1075 export PYTHONHASHSEED=$(python -c 'import random; print(random.randint(1, 4294967295))') -pytest pandas --skip-slow --skip-network -m "not single" -n 4 $@ +pytest pandas --skip-slow --skip-network -m "not single" -n 4 From befd85804009b45c7273dbc7d2b32b8de64853f5 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 4 Mar 2017 11:33:39 +0100 Subject: [PATCH 2/2] Revert "ENH: Added FrozenList difference setop" This reverts commit 37fe2c4edddbec2c08d561667897a1ef5a18771c. --- doc/source/groupby.rst | 10 --------- doc/source/whatsnew/v0.20.0.txt | 2 -- pandas/indexes/frozen.py | 24 +++------------------ pandas/tests/indexes/test_frozen.py | 33 ++++++++--------------------- 4 files changed, 12 insertions(+), 57 deletions(-) diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst index 2d406de7c0c9b..8484ccd69a983 100644 --- a/doc/source/groupby.rst +++ b/doc/source/groupby.rst @@ -126,16 +126,6 @@ We could naturally group by either the ``A`` or ``B`` columns or both: grouped = df.groupby('A') grouped = df.groupby(['A', 'B']) -.. versionadded:: 0.20 - -If we also have a MultiIndex on columns ``A`` and ``B``, we can group by all -but the specified columns. - -.. ipython:: python - - df2 = df.set_index(['A', 'B']) - grouped = df2.groupby(level=df2.index.names.difference(['B']) - These will split the DataFrame on its index (rows). We could also split by the columns: diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index df259f4a42b86..c172b28a79ec4 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -28,7 +28,6 @@ New features - Integration with the ``feather-format``, including a new top-level ``pd.read_feather()`` and ``DataFrame.to_feather()`` method, see :ref:`here `. - ``.str.replace`` now accepts a callable, as replacement, which is passed to ``re.sub`` (:issue:`15055`) -- ``FrozenList`` has gained the ``.difference()`` setop method (:issue:`15475`) @@ -536,7 +535,6 @@ Deprecations - ``Series.sortlevel`` and ``DataFrame.sortlevel`` have been deprecated in favor of ``Series.sort_index`` and ``DataFrame.sort_index`` (:issue:`15099`) - importing ``concat`` from ``pandas.tools.merge`` has been deprecated in favor of imports from the ``pandas`` namespace. This should only affect explict imports (:issue:`15358`) - ``Series/DataFrame/Panel.consolidate()`` been deprecated as a public method. (:issue:`15483`) -- ``FrozenList`` addition (new object and inplace) have been deprecated in favor of the ``.union()`` method. (:issue: `15475`) - The following top-level pandas functions have been deprecated and will be removed in a future version (:issue:`13790`) * ``pd.pnow()``, replaced by ``Period.now()`` * ``pd.Term``, is removed, as it is not applicable to user code. Instead use in-line string expressions in the where clause when searching in HDFStore diff --git a/pandas/indexes/frozen.py b/pandas/indexes/frozen.py index 47e2557333ec7..e043ba64bbad7 100644 --- a/pandas/indexes/frozen.py +++ b/pandas/indexes/frozen.py @@ -13,8 +13,6 @@ from pandas.types.cast import _coerce_indexer_dtype from pandas.formats.printing import pprint_thing -import warnings - class FrozenList(PandasObject, list): @@ -27,14 +25,11 @@ class FrozenList(PandasObject, list): # typechecks def __add__(self, other): - warnings.warn("__add__ is deprecated, use union(...)", FutureWarning) - return self.union(other) - - def __iadd__(self, other): - warnings.warn("__iadd__ is deprecated, use union(...)", FutureWarning) if isinstance(other, tuple): other = list(other) - return super(FrozenList, self).__iadd__(other) + return self.__class__(super(FrozenList, self).__add__(other)) + + __iadd__ = __add__ # Python 2 compat def __getslice__(self, i, j): @@ -85,19 +80,6 @@ def __repr__(self): __setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled pop = append = extend = remove = sort = insert = _disabled - def union(self, other): - """Returns a FrozenList with other concatenated to the end of self""" - if isinstance(other, tuple): - other = list(other) - return self.__class__(super(FrozenList, self).__add__(other)) - - def difference(self, other): - """Returns a FrozenList with the same elements as self, but with elements - that are also in other removed.""" - other = set(other) - temp = [x for x in self if x not in other] - return self.__class__(temp) - class FrozenNDArray(PandasObject, np.ndarray): diff --git a/pandas/tests/indexes/test_frozen.py b/pandas/tests/indexes/test_frozen.py index a5fbf066adc83..a82409fbf9513 100644 --- a/pandas/tests/indexes/test_frozen.py +++ b/pandas/tests/indexes/test_frozen.py @@ -15,35 +15,20 @@ def setUp(self): self.klass = FrozenList def test_add(self): - q = FrozenList([1]) - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - q = q + [2, 3] - expected = FrozenList([1, 2, 3]) - self.check_result(q, expected) - - def test_iadd(self): - q = FrozenList([1]) - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - q += [2, 3] - expected = FrozenList([1, 2, 3]) - self.check_result(q, expected) - - def test_union(self): - result = self.container.union((1, 2, 3)) + result = self.container + (1, 2, 3) expected = FrozenList(self.lst + [1, 2, 3]) self.check_result(result, expected) - def test_difference(self): - result = self.container.difference([2]) - expected = FrozenList([1, 3, 4, 5]) + result = (1, 2, 3) + self.container + expected = FrozenList([1, 2, 3] + self.lst) self.check_result(result, expected) - def test_difference_dupe(self): - result = FrozenList([1, 2, 3, 2]).difference([2]) - expected = FrozenList([1, 3]) - self.check_result(result, expected) + def test_inplace(self): + q = r = self.container + q += [5] + self.check_result(q, self.lst + [5]) + # other shouldn't be mutated + self.check_result(r, self.lst) class TestFrozenNDArray(CheckImmutable, CheckStringMixin, tm.TestCase):