Skip to content

API: Panel.dtypes to use generic method; add tests for Panel4D for same #5983

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
Jan 17, 2014
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
51 changes: 49 additions & 2 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ Attributes and underlying data

Series.values
Series.dtype
Series.isnull
Series.notnull
Series.ftype

Conversion
~~~~~~~~~~
Expand Down Expand Up @@ -519,7 +518,9 @@ Attributes and underlying data

DataFrame.as_matrix
DataFrame.dtypes
DataFrame.ftypes
DataFrame.get_dtype_counts
DataFrame.get_ftype_counts
DataFrame.values
DataFrame.axes
DataFrame.ndim
Expand Down Expand Up @@ -786,6 +787,9 @@ Attributes and underlying data
Panel.ndim
Panel.shape
Panel.dtypes
Panel.ftypes
Panel.get_dtype_counts
Panel.get_ftype_counts

Conversion
~~~~~~~~~~
Expand Down Expand Up @@ -959,6 +963,49 @@ Serialization / IO / Conversion
Panel.to_frame
Panel.to_clipboard

.. _api.panel4d:

Panel4D
-------

Constructor
~~~~~~~~~~~
.. autosummary::
:toctree: generated/

Panel4D

Attributes and underlying data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Axes**

* **labels**: axis 1; each label corresponds to a Panel contained inside
* **items**: axis 2; each item corresponds to a DataFrame contained inside
* **major_axis**: axis 3; the index (rows) of each of the DataFrames
* **minor_axis**: axis 4; the columns of each of the DataFrames

.. autosummary::
:toctree: generated/

Panel4D.values
Panel4D.axes
Panel4D.ndim
Panel4D.shape
Panel4D.dtypes
Panel4D.ftypes
Panel4D.get_dtype_counts
Panel4D.get_ftype_counts

Conversion
~~~~~~~~~~
.. autosummary::
:toctree: generated/

Panel4D.astype
Panel4D.copy
Panel4D.isnull
Panel4D.notnull

.. _api.index:

Index
Expand Down
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Improvements to existing features
- df.info() now honors option max_info_rows, disable null counts for large frames (:issue:`5974`)
- perf improvements in DataFrame ``count/dropna`` for ``axis=1``
- Series.str.contains now has a `regex=False` keyword which can be faster for plain (non-regex) string patterns. (:issue:`5879`)
- support ``dtypes`` on ``Panel``
- support ``dtypes`` property on ``Series/Panel/Panel4D``
- extend ``Panel.apply`` to allow arbitrary functions (rather than only ufuncs) (:issue:`1148`)
allow multiple axes to be used to operate on slabs of a ``Panel``
- The ``ArrayFormatter``s for ``datetime`` and ``timedelta64`` now intelligently
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,9 @@ def _post_setstate(self):
self._block = self.blocks[0]
self._values = self._block.values

def _get_counts(self, f):
return { f(self._block) : 1 }

@property
def shape(self):
if getattr(self, '_shape', None) is None:
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,6 @@ def as_matrix(self):
self._consolidate_inplace()
return self._data.as_matrix()

@property
def dtypes(self):
return self.apply(lambda x: x.dtype, axis='items')

#----------------------------------------------------------------------
# Getting and setting elements

Expand Down
12 changes: 11 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,20 @@ def flags(self):
def dtype(self):
return self._data.dtype

@property
def dtypes(self):
""" for compat """
return self._data.dtype

@property
def ftype(self):
return self._data.ftype

@property
def ftypes(self):
""" for compat """
return self._data.ftype

@property
def shape(self):
return self._data.shape
Expand Down Expand Up @@ -2094,7 +2104,7 @@ def isin(self, values):
----------
values : list-like
The sequence of values to test. Passing in a single string will
raise a ``TypeError``. Instead, turn a single string into a
raise a ``TypeError``. Instead, turn a single string into a
``list`` of one element.

Returns
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np

from pandas import DataFrame, Index, isnull, notnull, pivot, MultiIndex
from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex
from pandas.core.datetools import bday
from pandas.core.frame import group_agg
from pandas.core.panel import Panel
Expand Down Expand Up @@ -1064,8 +1064,8 @@ def test_convert_objects(self):
def test_dtypes(self):

result = self.panel.dtypes
expected = DataFrame(np.dtype('float64'),index=self.panel.major_axis,columns=self.panel.minor_axis)
assert_frame_equal(result, expected)
expected = Series(np.dtype('float64'),index=self.panel.items)
assert_series_equal(result, expected)

def test_apply(self):
# GH1148
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/test_panel4d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np

from pandas import DataFrame, Index, isnull, notnull, pivot, MultiIndex
from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex
from pandas.core.datetools import bday
from pandas.core.frame import group_agg
from pandas.core.panel import Panel
Expand Down Expand Up @@ -932,6 +932,12 @@ def test_filter(self):
def test_apply(self):
raise nose.SkipTest("skipping for now")

def test_dtypes(self):

result = self.panel4d.dtypes
expected = Series(np.dtype('float64'),index=self.panel4d.labels)
assert_series_equal(result, expected)

def test_compound(self):
raise nose.SkipTest("skipping for now")
# compounded = self.panel.compound()
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,15 @@ def test_count(self):

self.assertEqual(self.ts.count(), np.isfinite(self.ts).sum())

def test_dtype(self):

self.assert_(self.ts.dtype == np.dtype('float64'))
self.assert_(self.ts.dtypes == np.dtype('float64'))
self.assert_(self.ts.ftype == 'float64:dense')
self.assert_(self.ts.ftypes == 'float64:dense')
assert_series_equal(self.ts.get_dtype_counts(),Series(1,['float64']))
assert_series_equal(self.ts.get_ftype_counts(),Series(1,['float64:dense']))

def test_dot(self):
a = Series(np.random.randn(4), index=['p', 'q', 'r', 's'])
b = DataFrame(np.random.randn(3, 4), index=['1', '2', '3'],
Expand Down