diff --git a/doc/source/release.rst b/doc/source/release.rst index 47e0cfd78271e..789fbd0fe4ccc 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -437,7 +437,7 @@ Bug Fixes - Fixed ``_ensure_numeric`` does not check for complex numbers (:issue:`4902`) - Fixed a bug in ``Series.hist`` where two figures were being created when the ``by`` argument was passed (:issue:`4112`, :issue:`4113`). - + - Fixed a bug in ``convert_objects`` for > 2 ndims (:issue:`4937`) pandas 0.12.0 ------------- diff --git a/doc/source/v0.13.0.txt b/doc/source/v0.13.0.txt index 72b0212f77ac9..bc16f549f0cf1 100644 --- a/doc/source/v0.13.0.txt +++ b/doc/source/v0.13.0.txt @@ -331,7 +331,6 @@ Enhancements can also be used. - ``read_stata` now accepts Stata 13 format (:issue:`4291`) - .. _whatsnew_0130.experimental: Experimental diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 585b1c817ff19..3ab1bfb2c58ed 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1164,8 +1164,8 @@ def convert(self, convert_dates=True, convert_numeric=True, copy=True, by_item=T values = self.iget(i) values = com._possibly_convert_objects( - values, convert_dates=convert_dates, convert_numeric=convert_numeric) - values = _block_shape(values) + values.ravel(), convert_dates=convert_dates, convert_numeric=convert_numeric).reshape(values.shape) + values = _block_shape(values, ndim=self.ndim) items = self.items.take([i]) placement = None if is_unique else [i] newb = make_block( @@ -1175,7 +1175,7 @@ def convert(self, convert_dates=True, convert_numeric=True, copy=True, by_item=T else: values = com._possibly_convert_objects( - self.values, convert_dates=convert_dates, convert_numeric=convert_numeric) + self.values.ravel(), convert_dates=convert_dates, convert_numeric=convert_numeric).reshape(self.values.shape) blocks.append( make_block(values, self.items, self.ref_items, ndim=self.ndim)) @@ -3610,7 +3610,7 @@ def _merge_blocks(blocks, items, dtype=None, _can_consolidate=True): def _block_shape(values, ndim=1, shape=None): """ guarantee the shape of the values to be at least 1 d """ - if values.ndim == ndim: + if values.ndim <= ndim: if shape is None: shape = values.shape values = values.reshape(tuple((1,) + shape)) diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index a498cca528043..0195fe30a05c8 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -1010,6 +1010,14 @@ def test_conform(self): assert(conformed.index.equals(self.panel.major_axis)) assert(conformed.columns.equals(self.panel.minor_axis)) + def test_convert_objects(self): + + # GH 4937 + p = Panel(dict(A = dict(a = ['1','1.0']))) + expected = Panel(dict(A = dict(a = [1,1.0]))) + result = p.convert_objects(convert_numeric='force') + assert_panel_equal(result, expected) + def test_reindex(self): ref = self.panel['ItemB'] @@ -1287,9 +1295,6 @@ def test_to_panel_duplicates(self): def test_filter(self): pass - def test_apply(self): - pass - def test_compound(self): compounded = self.panel.compound() @@ -1350,7 +1355,7 @@ def test_tshift(self): assert_panel_equal(shifted, shifted2) inferred_ts = Panel(panel.values, - items=panel.items, + items=panel.items, major_axis=Index(np.asarray(panel.major_axis)), minor_axis=panel.minor_axis) shifted = inferred_ts.tshift(1)