Skip to content

BUG: Fixed a bug in convert_objects for > 2 ndims GH4937 #4938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down
1 change: 0 additions & 1 deletion doc/source/v0.13.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ Enhancements
can also be used.
- ``read_stata` now accepts Stata 13 format (:issue:`4291`)


.. _whatsnew_0130.experimental:

Experimental
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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))

Expand Down Expand Up @@ -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))
Expand Down
13 changes: 9 additions & 4 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down