Repository: pandas-dev/pandas

Issue:
sort_values not implemented for Panel
#### Code Sample, a copy-pastable example if possible

```python
import pandas as pd
pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2']).sort_values(by=0)

---------------------------------------------------------------------------
AbstractMethodError                       Traceback (most recent call last)
<ipython-input-16-f14e23e389bd> in <module>()
      1 import pandas as pd
----> 2 pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2']).sort_values(by=0)

/home/gpepe/software/anaconda3/envs/science/lib/python3.6/site-packages/pandas/core/generic.py in sort_values(self, by, axis, ascending, inplace, kind, na_position)
   2010     def sort_values(self, by, axis=0, ascending=True, inplace=False,
   2011                     kind='quicksort', na_position='last'):
-> 2012         raise AbstractMethodError(self)
   2013 
   2014     _shared_docs['sort_index'] = """

AbstractMethodError: This method must be defined in the concrete class of Panel

```
#### Problem description

It seems like the sort_values() method is not implemented in Panels, but it is not clear from the raised error message. There seems to be a page on this in the API reference: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Panel.sort_values.html. i would find it highly useful to have such a method.

#### Expected Output

Sorted panel

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------

commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Linux
OS-release: 3.16.0-4-amd64
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: en_GB.utf8
LOCALE: en_GB.UTF-8

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
boto: 2.45.0
pandas_datareader: None

</details>



Discussion:
@pepicello Thanks for the report. You are correct it is not the best error message, although it indicates that the method does not defined. The doc page should better reflect that (PR welcome to update that!).

Note that Panels will be deprecated (https://github.com/pandas-dev/pandas/issues/13563, merged in master, will be in the upcoming 0.20 releases), so we probably are not going to expand its functionality.

Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -2366,9 +2366,14 @@ def add_suffix(self, suffix):
         1   A    1    1
         """
 
-    def sort_values(self, by, axis=0, ascending=True, inplace=False,
+    def sort_values(self, by=None, axis=0, ascending=True, inplace=False,
                     kind='quicksort', na_position='last'):
-        raise AbstractMethodError(self)
+        """
+        NOT IMPLEMENTED: do not call this method, as sorting values is not
+        supported for Panel objects and will raise an error.
+        """
+        raise NotImplementedError("sort_values has not been implemented "
+                                  "on Panel or Panel4D objects.")
 
     _shared_docs['sort_index'] = """
         Sort object by labels (along an axis)


Test patch:
diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py
--- a/pandas/tests/test_panel.py
+++ b/pandas/tests/test_panel.py
@@ -2429,6 +2429,11 @@ def test_all_any_unhandled(self):
         pytest.raises(NotImplementedError, self.panel.all, bool_only=True)
         pytest.raises(NotImplementedError, self.panel.any, bool_only=True)
 
+    # GH issue 15960
+    def test_sort_values(self):
+        pytest.raises(NotImplementedError, self.panel.sort_values)
+        pytest.raises(NotImplementedError, self.panel.sort_values, 'ItemA')
+
 
 class TestLongPanel(object):
     """
diff --git a/pandas/tests/test_panel4d.py b/pandas/tests/test_panel4d.py
--- a/pandas/tests/test_panel4d.py
+++ b/pandas/tests/test_panel4d.py
@@ -939,3 +939,8 @@ def test_rename(self):
 
     def test_get_attr(self):
         tm.assert_panel_equal(self.panel4d['l1'], self.panel4d.l1)
+
+    # GH issue 15960
+    def test_sort_values(self):
+        pytest.raises(NotImplementedError, self.panel4d.sort_values)
+        pytest.raises(NotImplementedError, self.panel4d.sort_values, 'ItemA')