Skip to content

Commit dc3175e

Browse files
committed
Merge pull request #5983 from jreback/panel_dtypes
API: Panel.dtypes to use generic method; add tests for Panel4D for same
2 parents d54f77a + e4e5a71 commit dc3175e

File tree

8 files changed

+83
-12
lines changed

8 files changed

+83
-12
lines changed

doc/source/api.rst

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ Attributes and underlying data
249249

250250
Series.values
251251
Series.dtype
252-
Series.isnull
253-
Series.notnull
252+
Series.ftype
254253

255254
Conversion
256255
~~~~~~~~~~
@@ -519,7 +518,9 @@ Attributes and underlying data
519518

520519
DataFrame.as_matrix
521520
DataFrame.dtypes
521+
DataFrame.ftypes
522522
DataFrame.get_dtype_counts
523+
DataFrame.get_ftype_counts
523524
DataFrame.values
524525
DataFrame.axes
525526
DataFrame.ndim
@@ -786,6 +787,9 @@ Attributes and underlying data
786787
Panel.ndim
787788
Panel.shape
788789
Panel.dtypes
790+
Panel.ftypes
791+
Panel.get_dtype_counts
792+
Panel.get_ftype_counts
789793

790794
Conversion
791795
~~~~~~~~~~
@@ -959,6 +963,49 @@ Serialization / IO / Conversion
959963
Panel.to_frame
960964
Panel.to_clipboard
961965

966+
.. _api.panel4d:
967+
968+
Panel4D
969+
-------
970+
971+
Constructor
972+
~~~~~~~~~~~
973+
.. autosummary::
974+
:toctree: generated/
975+
976+
Panel4D
977+
978+
Attributes and underlying data
979+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
980+
**Axes**
981+
982+
* **labels**: axis 1; each label corresponds to a Panel contained inside
983+
* **items**: axis 2; each item corresponds to a DataFrame contained inside
984+
* **major_axis**: axis 3; the index (rows) of each of the DataFrames
985+
* **minor_axis**: axis 4; the columns of each of the DataFrames
986+
987+
.. autosummary::
988+
:toctree: generated/
989+
990+
Panel4D.values
991+
Panel4D.axes
992+
Panel4D.ndim
993+
Panel4D.shape
994+
Panel4D.dtypes
995+
Panel4D.ftypes
996+
Panel4D.get_dtype_counts
997+
Panel4D.get_ftype_counts
998+
999+
Conversion
1000+
~~~~~~~~~~
1001+
.. autosummary::
1002+
:toctree: generated/
1003+
1004+
Panel4D.astype
1005+
Panel4D.copy
1006+
Panel4D.isnull
1007+
Panel4D.notnull
1008+
9621009
.. _api.index:
9631010

9641011
Index

doc/source/release.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Improvements to existing features
7575
- df.info() now honors option max_info_rows, disable null counts for large frames (:issue:`5974`)
7676
- perf improvements in DataFrame ``count/dropna`` for ``axis=1``
7777
- Series.str.contains now has a `regex=False` keyword which can be faster for plain (non-regex) string patterns. (:issue:`5879`)
78-
- support ``dtypes`` on ``Panel``
78+
- support ``dtypes`` property on ``Series/Panel/Panel4D``
7979
- extend ``Panel.apply`` to allow arbitrary functions (rather than only ufuncs) (:issue:`1148`)
8080
allow multiple axes to be used to operate on slabs of a ``Panel``
8181
- The ``ArrayFormatter``s for ``datetime`` and ``timedelta64`` now intelligently

pandas/core/internals.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,6 +3514,9 @@ def _post_setstate(self):
35143514
self._block = self.blocks[0]
35153515
self._values = self._block.values
35163516

3517+
def _get_counts(self, f):
3518+
return { f(self._block) : 1 }
3519+
35173520
@property
35183521
def shape(self):
35193522
if getattr(self, '_shape', None) is None:

pandas/core/panel.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,6 @@ def as_matrix(self):
441441
self._consolidate_inplace()
442442
return self._data.as_matrix()
443443

444-
@property
445-
def dtypes(self):
446-
return self.apply(lambda x: x.dtype, axis='items')
447-
448444
#----------------------------------------------------------------------
449445
# Getting and setting elements
450446

pandas/core/series.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,20 @@ def flags(self):
301301
def dtype(self):
302302
return self._data.dtype
303303

304+
@property
305+
def dtypes(self):
306+
""" for compat """
307+
return self._data.dtype
308+
304309
@property
305310
def ftype(self):
306311
return self._data.ftype
307312

313+
@property
314+
def ftypes(self):
315+
""" for compat """
316+
return self._data.ftype
317+
308318
@property
309319
def shape(self):
310320
return self._data.shape
@@ -2094,7 +2104,7 @@ def isin(self, values):
20942104
----------
20952105
values : list-like
20962106
The sequence of values to test. Passing in a single string will
2097-
raise a ``TypeError``. Instead, turn a single string into a
2107+
raise a ``TypeError``. Instead, turn a single string into a
20982108
``list`` of one element.
20992109
21002110
Returns

pandas/tests/test_panel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88

9-
from pandas import DataFrame, Index, isnull, notnull, pivot, MultiIndex
9+
from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex
1010
from pandas.core.datetools import bday
1111
from pandas.core.frame import group_agg
1212
from pandas.core.panel import Panel
@@ -1064,8 +1064,8 @@ def test_convert_objects(self):
10641064
def test_dtypes(self):
10651065

10661066
result = self.panel.dtypes
1067-
expected = DataFrame(np.dtype('float64'),index=self.panel.major_axis,columns=self.panel.minor_axis)
1068-
assert_frame_equal(result, expected)
1067+
expected = Series(np.dtype('float64'),index=self.panel.items)
1068+
assert_series_equal(result, expected)
10691069

10701070
def test_apply(self):
10711071
# GH1148

pandas/tests/test_panel4d.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88

9-
from pandas import DataFrame, Index, isnull, notnull, pivot, MultiIndex
9+
from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex
1010
from pandas.core.datetools import bday
1111
from pandas.core.frame import group_agg
1212
from pandas.core.panel import Panel
@@ -932,6 +932,12 @@ def test_filter(self):
932932
def test_apply(self):
933933
raise nose.SkipTest("skipping for now")
934934

935+
def test_dtypes(self):
936+
937+
result = self.panel4d.dtypes
938+
expected = Series(np.dtype('float64'),index=self.panel4d.labels)
939+
assert_series_equal(result, expected)
940+
935941
def test_compound(self):
936942
raise nose.SkipTest("skipping for now")
937943
# compounded = self.panel.compound()

pandas/tests/test_series.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,15 @@ def test_count(self):
36203620

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

3623+
def test_dtype(self):
3624+
3625+
self.assert_(self.ts.dtype == np.dtype('float64'))
3626+
self.assert_(self.ts.dtypes == np.dtype('float64'))
3627+
self.assert_(self.ts.ftype == 'float64:dense')
3628+
self.assert_(self.ts.ftypes == 'float64:dense')
3629+
assert_series_equal(self.ts.get_dtype_counts(),Series(1,['float64']))
3630+
assert_series_equal(self.ts.get_ftype_counts(),Series(1,['float64:dense']))
3631+
36233632
def test_dot(self):
36243633
a = Series(np.random.randn(4), index=['p', 'q', 'r', 's'])
36253634
b = DataFrame(np.random.randn(3, 4), index=['1', '2', '3'],

0 commit comments

Comments
 (0)