From dd5d78be04f689f4224b4a212e51d26429d3c0ad Mon Sep 17 00:00:00 2001 From: jreback Date: Tue, 18 Mar 2014 08:17:48 -0400 Subject: [PATCH] BUG: Bug in compat with np.compress, surfaced in (GH6658) --- doc/source/release.rst | 9 +++++---- pandas/core/series.py | 4 ++++ pandas/tests/test_series.py | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index 7cf2bec0f4144..5510d70c1e0f7 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -126,9 +126,9 @@ API Changes DataFrame returned by ``GroupBy.apply`` (:issue:`6124`). This facilitates ``DataFrame.stack`` operations where the name of the column index is used as the name of the inserted column containing the pivoted data. - -- The :func:`pivot_table`/:meth:`DataFrame.pivot_table` and :func:`crosstab` functions - now take arguments ``index`` and ``columns`` instead of ``rows`` and ``cols``. A + +- The :func:`pivot_table`/:meth:`DataFrame.pivot_table` and :func:`crosstab` functions + now take arguments ``index`` and ``columns`` instead of ``rows`` and ``cols``. A ``FutureWarning`` is raised to alert that the old ``rows`` and ``cols`` arguments will not be supported in a future release (:issue:`5505`) @@ -175,7 +175,7 @@ Improvements to existing features - ``StataWriter`` and ``DataFrame.to_stata`` accept time stamp and data labels (:issue:`6545`) - offset/freq info now in Timestamp __repr__ (:issue:`4553`) - Support passing ``encoding`` with xlwt (:issue:`3710`) -- Performance improvement when converting ``DatetimeIndex`` to floating ordinals +- Performance improvement when converting ``DatetimeIndex`` to floating ordinals using ``DatetimeConverter`` (:issue:`6636`) .. _release.bug_fixes-0.14.0: @@ -259,6 +259,7 @@ Bug Fixes - Bug in ``iloc`` indexing when positional indexer matched Int64Index of corresponding axis no reordering happened (:issue:`6612`) - Bug in ``fillna`` with ``limit`` and ``value`` specified - Bug in ``DataFrame.to_stata`` when columns have non-string names (:issue:`4558`) +- Bug in compat with ``np.compress``, surfaced in (:issue:`6658`) pandas 0.13.1 ------------- diff --git a/pandas/core/series.py b/pandas/core/series.py index dd11b7bec9216..60429630eb7d3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -342,6 +342,10 @@ def base(self): def ravel(self, order='C'): return self.values.ravel(order=order) + def compress(self, condition, axis=0, out=None, **kwargs): + # 1-d compat with numpy + return self[condition] + def transpose(self): """ support for compatiblity """ return self diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index b90cdcf55f636..a94ca5dfc1075 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -3436,6 +3436,15 @@ def f(x): s = Series(np.random.randn(10)) tm.assert_almost_equal(s.ravel(order='F'),s.values.ravel(order='F')) + # compress + # GH 6658 + s = Series([0,1.,-1],index=list('abc')) + result = np.compress(s>0,s) + assert_series_equal(result, Series([1.],index=['b'])) + + result = np.compress(s<-1,s) + assert_series_equal(result, Series([],dtype='float64')) + def test_complexx(self): # GH4819