diff --git a/doc/source/api.rst b/doc/source/api.rst index 79f5af74c3985..b21cd1456a5fd 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -249,8 +249,7 @@ Attributes and underlying data Series.values Series.dtype - Series.isnull - Series.notnull + Series.ftype Conversion ~~~~~~~~~~ @@ -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 @@ -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 ~~~~~~~~~~ @@ -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 diff --git a/doc/source/release.rst b/doc/source/release.rst index c5dc55f260f64..99b8bfc460068 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -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 diff --git a/pandas/core/internals.py b/pandas/core/internals.py index ca16be1b52ca2..fbea40eb76a0d 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -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: diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 832874f08561b..fc4373764172f 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -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 diff --git a/pandas/core/series.py b/pandas/core/series.py index 2e1d95cf87b47..918043dcacd37 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 @@ -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 diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 2589f7b82aedb..16a43f2f9e767 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -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 @@ -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 diff --git a/pandas/tests/test_panel4d.py b/pandas/tests/test_panel4d.py index ea6602dbb0be6..fb5030ac66831 100644 --- a/pandas/tests/test_panel4d.py +++ b/pandas/tests/test_panel4d.py @@ -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 @@ -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() diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 699ffb592a63e..70dd38c2641ef 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -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'],