9
9
from pandas .core .frame import DataFrame
10
10
11
11
from pandas .core .categorical import Categorical
12
- from pandas .core .common import notnull , _ensure_platform_int
12
+ from pandas .core .common import (notnull , _ensure_platform_int , _maybe_promote ,
13
+ _maybe_upcast )
13
14
from pandas .core .groupby import (get_group_index , _compress_group_index ,
14
15
decons_group_index )
15
16
import pandas .core .common as com
@@ -148,11 +149,9 @@ def get_new_values(self):
148
149
stride = values .shape [1 ]
149
150
result_width = width * stride
150
151
151
- new_values = np .empty ((length , result_width ), dtype = values .dtype )
152
- new_mask = np .zeros ((length , result_width ), dtype = bool )
153
-
154
- new_values = com ._maybe_upcast (new_values )
152
+ new_values = np .empty ((length , result_width ), dtype = _maybe_promote (values .dtype ))
155
153
new_values .fill (np .nan )
154
+ new_mask = np .zeros ((length , result_width ), dtype = bool )
156
155
157
156
# is there a simpler / faster way of doing this?
158
157
for i in xrange (values .shape [1 ]):
@@ -761,40 +760,6 @@ def make_axis_dummies(frame, axis='minor', transform=None):
761
760
return DataFrame (values , columns = items , index = frame .index )
762
761
763
762
764
- def block2d_to_block3d (values , items , shape , major_labels , minor_labels ,
765
- ref_items = None ):
766
- """
767
- Developer method for pivoting DataFrame -> Panel. Used in HDFStore and
768
- DataFrame.to_panel
769
- """
770
- from pandas .core .internals import make_block
771
- panel_shape = (len (items ),) + shape
772
-
773
- # TODO: lexsort depth needs to be 2!!
774
-
775
- # Create observation selection vector using major and minor
776
- # labels, for converting to panel format.
777
- selector = minor_labels + shape [1 ] * major_labels
778
- mask = np .zeros (np .prod (shape ), dtype = bool )
779
- mask .put (selector , True )
780
-
781
- pvalues = np .empty (panel_shape , dtype = values .dtype )
782
- if not issubclass (pvalues .dtype .type , (np .integer , np .bool_ )):
783
- pvalues .fill (np .nan )
784
- elif not mask .all ():
785
- pvalues = com ._maybe_upcast (pvalues )
786
- pvalues .fill (np .nan )
787
-
788
- values = values
789
- for i in xrange (len (items )):
790
- pvalues [i ].flat [mask ] = values [:, i ]
791
-
792
- if ref_items is None :
793
- ref_items = items
794
-
795
- return make_block (pvalues , items , ref_items )
796
-
797
-
798
763
def block2d_to_blocknd (values , items , shape , labels , ref_items = None ):
799
764
""" pivot to the labels shape """
800
765
from pandas .core .internals import make_block
@@ -812,7 +777,7 @@ def block2d_to_blocknd(values, items, shape, labels, ref_items=None):
812
777
if not issubclass (pvalues .dtype .type , (np .integer , np .bool_ )):
813
778
pvalues .fill (np .nan )
814
779
elif not mask .all ():
815
- pvalues = com . _maybe_upcast (pvalues )
780
+ pvalues = _maybe_upcast (pvalues )
816
781
pvalues .fill (np .nan )
817
782
818
783
values = values
0 commit comments