Permalink
Browse files

BUG: index integer name format bug, plus handle non-string columns in…

… groupby, GH #405
  • Loading branch information...
1 parent eaf38f9 commit ef7676493ae6a4b48f6a439cb0968c0532df69e5 @wesm wesm committed Nov 23, 2011
Showing with 24 additions and 3 deletions.
  1. +2 −0 RELEASE.rst
  2. +4 −1 pandas/core/groupby.py
  3. +1 −1 pandas/core/index.py
  4. +1 −1 pandas/core/series.py
  5. +8 −0 pandas/tests/test_groupby.py
  6. +8 −0 pandas/tests/test_index.py
View
@@ -154,6 +154,8 @@ pandas 0.6.0
- Enable partial setting with .ix / advanced indexing (GH #397)
- Handle mixed-type DataFrames correctly in unstack, do not lose type
information (GH #403)
+ - Fix integer name formatting bug in Index.format and in Series.__repr__
+ - Handle label types other than string passed to groupby (GH #405)
Thanks
------
View
@@ -633,7 +633,7 @@ def _get_groupings(obj, grouper=None, axis=0, level=None):
exclusions = []
for i, (gpr, level) in enumerate(zip(groupers, levels)):
name = None
- if isinstance(gpr, basestring):
+ if _is_label_like(gpr):
exclusions.append(gpr)
name = gpr
gpr = obj[gpr]
@@ -644,6 +644,9 @@ def _get_groupings(obj, grouper=None, axis=0, level=None):
return groupings, exclusions
+def _is_label_like(val):
+ return isinstance(val, basestring) or np.isscalar(val)
+
def _convert_grouper(axis, grouper):
if isinstance(grouper, dict):
return grouper.get
View
@@ -206,7 +206,7 @@ def format(self, name=False):
result = []
if name:
- result.append(self.name if self.name is not None else '')
+ result.append(str(self.name) if self.name is not None else '')
if self.is_all_dates():
zero_time = time(0, 0)
View
@@ -410,7 +410,7 @@ def _get_repr(self, name=False, print_header=False, length=True,
header, string_index = string_index[0], string_index[1:]
else:
have_header = index.name is not None
- header = index.name
+ header = str(index.name)
string_index = index.format()
maxlen = max(len(x) for x in string_index)
@@ -1026,6 +1026,14 @@ def test_groupby_series_with_name(self):
self.assert_('A' in result2)
self.assert_('B' in result2)
+ def test_groupby_nonstring_columns(self):
+ df = DataFrame([np.arange(10) for x in range(10)])
+ grouped = df.groupby(0)
+ result = grouped.mean()
+ expected = df.groupby(df[0]).mean()
+ del expected[0]
+ assert_frame_equal(result, expected)
+
class TestPanelGroupBy(unittest.TestCase):
def setUp(self):
@@ -588,6 +588,14 @@ def test_take_preserve_name(self):
taken = index.take([3,0,1])
self.assertEqual(index.name, taken.name)
+ def test_int_name_format(self):
+ from pandas import Series, DataFrame
+ index = Index(['a', 'b', 'c'], name=0)
+ s = Series(range(3), index)
+ df = DataFrame(range(3), index=index)
+ repr(s)
+ repr(df)
+
class TestMultiIndex(unittest.TestCase):
def setUp(self):

0 comments on commit ef76764

Please sign in to comment.