Skip to content

Commit

Permalink
BUG: Panel.from_dict does not set dtype when specified
Browse files Browse the repository at this point in the history
  • Loading branch information
mortada committed May 16, 2015
1 parent d03a22f commit 9b4d154
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Bug Fixes
- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)


- Bug where Panel.from_dict does not set dtype when specified (:issue:`10058`)
- Bug in ``Timestamp``'s' ``microsecond``, ``quarter``, ``dayofyear``, ``week`` and ``daysinmonth`` properties return ``np.int`` type, not built-in ``int``. (:issue:`10050`)
- Bug in ``NaT`` raises ``AttributeError`` when accessing to ``daysinmonth``, ``dayofweek`` properties. (:issue:`10096`)

Expand Down
2 changes: 2 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ def from_dict(cls, data, orient='columns', dtype=None):
The "orientation" of the data. If the keys of the passed dict
should be the columns of the resulting DataFrame, pass 'columns'
(default). Otherwise if the keys should be rows, pass 'index'.
dtype : dtype, default None
Data type to force, otherwise infer
Returns
-------
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None):
(default). Otherwise if the columns of the values of the passed
DataFrame objects should be the items (which in the case of
mixed-dtype data you should do), instead pass 'minor'
dtype : dtype, default None
Data type to force, otherwise infer
Returns
-------
Expand Down Expand Up @@ -1383,6 +1384,7 @@ def _homogenize_dict(self, frames, intersect=True, dtype=None):
result[key] = None

axes_dict['data'] = result
axes_dict['dtype'] = dtype
return axes_dict

@staticmethod
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,12 @@ def _check_dtype(panel, dtype):
panel = Panel(np.random.randn(2,10,5),items=lrange(2),major_axis=lrange(10),minor_axis=lrange(5),dtype=dtype)
_check_dtype(panel,dtype)

for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
df1 = DataFrame(np.random.randn(2, 5), index=lrange(2), columns=lrange(5))
df2 = DataFrame(np.random.randn(2, 5), index=lrange(2), columns=lrange(5))
panel = Panel.from_dict({'a': df1, 'b': df2}, dtype=dtype)
_check_dtype(panel, dtype)

def test_constructor_fails_with_not_3d_input(self):
with tm.assertRaisesRegexp(ValueError,
"The number of dimensions required is 3"):
Expand Down

0 comments on commit 9b4d154

Please sign in to comment.