Skip to content

Commit 0eab187

Browse files
committed
Merge pull request #4938 from jreback/panel_convert
BUG: Fixed a bug in convert_objects for > 2 ndims GH4937
2 parents 16e2f63 + 59fd29f commit 0eab187

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

doc/source/release.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ Bug Fixes
437437
- Fixed ``_ensure_numeric`` does not check for complex numbers (:issue:`4902`)
438438
- Fixed a bug in ``Series.hist`` where two figures were being created when
439439
the ``by`` argument was passed (:issue:`4112`, :issue:`4113`).
440-
440+
- Fixed a bug in ``convert_objects`` for > 2 ndims (:issue:`4937`)
441441

442442
pandas 0.12.0
443443
-------------

doc/source/v0.13.0.txt

-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ Enhancements
331331
can also be used.
332332
- ``read_stata` now accepts Stata 13 format (:issue:`4291`)
333333

334-
335334
.. _whatsnew_0130.experimental:
336335

337336
Experimental

pandas/core/internals.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ def convert(self, convert_dates=True, convert_numeric=True, copy=True, by_item=T
11641164
values = self.iget(i)
11651165

11661166
values = com._possibly_convert_objects(
1167-
values, convert_dates=convert_dates, convert_numeric=convert_numeric)
1168-
values = _block_shape(values)
1167+
values.ravel(), convert_dates=convert_dates, convert_numeric=convert_numeric).reshape(values.shape)
1168+
values = _block_shape(values, ndim=self.ndim)
11691169
items = self.items.take([i])
11701170
placement = None if is_unique else [i]
11711171
newb = make_block(
@@ -1175,7 +1175,7 @@ def convert(self, convert_dates=True, convert_numeric=True, copy=True, by_item=T
11751175
else:
11761176

11771177
values = com._possibly_convert_objects(
1178-
self.values, convert_dates=convert_dates, convert_numeric=convert_numeric)
1178+
self.values.ravel(), convert_dates=convert_dates, convert_numeric=convert_numeric).reshape(self.values.shape)
11791179
blocks.append(
11801180
make_block(values, self.items, self.ref_items, ndim=self.ndim))
11811181

@@ -3610,7 +3610,7 @@ def _merge_blocks(blocks, items, dtype=None, _can_consolidate=True):
36103610

36113611
def _block_shape(values, ndim=1, shape=None):
36123612
""" guarantee the shape of the values to be at least 1 d """
3613-
if values.ndim == ndim:
3613+
if values.ndim <= ndim:
36143614
if shape is None:
36153615
shape = values.shape
36163616
values = values.reshape(tuple((1,) + shape))

pandas/tests/test_panel.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,14 @@ def test_conform(self):
10101010
assert(conformed.index.equals(self.panel.major_axis))
10111011
assert(conformed.columns.equals(self.panel.minor_axis))
10121012

1013+
def test_convert_objects(self):
1014+
1015+
# GH 4937
1016+
p = Panel(dict(A = dict(a = ['1','1.0'])))
1017+
expected = Panel(dict(A = dict(a = [1,1.0])))
1018+
result = p.convert_objects(convert_numeric='force')
1019+
assert_panel_equal(result, expected)
1020+
10131021
def test_reindex(self):
10141022
ref = self.panel['ItemB']
10151023

@@ -1287,9 +1295,6 @@ def test_to_panel_duplicates(self):
12871295
def test_filter(self):
12881296
pass
12891297

1290-
def test_apply(self):
1291-
pass
1292-
12931298
def test_compound(self):
12941299
compounded = self.panel.compound()
12951300

@@ -1350,7 +1355,7 @@ def test_tshift(self):
13501355
assert_panel_equal(shifted, shifted2)
13511356

13521357
inferred_ts = Panel(panel.values,
1353-
items=panel.items,
1358+
items=panel.items,
13541359
major_axis=Index(np.asarray(panel.major_axis)),
13551360
minor_axis=panel.minor_axis)
13561361
shifted = inferred_ts.tshift(1)

0 commit comments

Comments
 (0)