1
- from .pandas_vb_common import *
1
+ import numpy as np
2
+ import pandas .util .testing as tm
3
+ from pandas import DataFrame , Series , MultiIndex
4
+ from pandas import *
2
5
try :
3
6
from pandas .tseries .offsets import *
4
7
except :
9
12
# Creation from nested dict
10
13
11
14
class FromDicts (object ):
15
+
12
16
goal_time = 0.2
13
17
14
18
def setup (self ):
15
- (N , K ) = (5000 , 50 )
19
+ np .random .seed (1234 )
20
+ N , K = 5000 , 50
16
21
self .index = tm .makeStringIndex (N )
17
22
self .columns = tm .makeStringIndex (K )
18
- self .frame = DataFrame (np .random .randn (N , K ), index = self .index , columns = self .columns )
19
- try :
20
- self .data = self .frame .to_dict ()
21
- except :
22
- self .data = self .frame .toDict ()
23
+ self .frame = DataFrame (np .random .randn (N , K ),
24
+ index = self .index ,
25
+ columns = self .columns )
26
+ self .data = self .frame .to_dict ()
23
27
self .some_dict = list (self .data .values ())[0 ]
24
- self .dict_list = [dict (zip (self .columns , row )) for row in self .frame .values ]
25
-
28
+ self .dict_list = self .frame .to_dict (orient = 'records' )
26
29
self .data2 = {i : {j : float (j ) for j in range (100 )}
27
30
for i in range (2000 )}
28
31
29
-
30
32
def time_frame_ctor_list_of_dict (self ):
31
33
DataFrame (self .dict_list )
32
34
@@ -38,38 +40,21 @@ def time_series_ctor_from_dict(self):
38
40
39
41
def time_frame_ctor_nested_dict_int64 (self ):
40
42
# nested dict, integer indexes, regression described in #621
41
- DataFrame (self .data )
43
+ DataFrame (self .data2 )
42
44
43
45
44
46
# from a mi-series
45
47
46
- class frame_from_series (object ):
48
+ class FromSeries (object ):
47
49
goal_time = 0.2
48
50
49
51
def setup (self ):
50
- self .mi = MultiIndex .from_tuples ([( x , y ) for x in range (100 ) for y in range (100 )])
51
- self .s = Series (randn (10000 ), index = self .mi )
52
+ self .mi = MultiIndex .from_product ([ range (100 ), range (100 )])
53
+ self .s = Series (np . random . randn (10000 ), index = self .mi )
52
54
53
55
def time_frame_from_mi_series (self ):
54
56
DataFrame (self .s )
55
57
56
-
57
- #----------------------------------------------------------------------
58
- # get_numeric_data
59
-
60
- class frame_get_numeric_data (object ):
61
- goal_time = 0.2
62
-
63
- def setup (self ):
64
- self .df = DataFrame (randn (10000 , 25 ))
65
- self .df ['foo' ] = 'bar'
66
- self .df ['bar' ] = 'baz'
67
- self .df = self .df .consolidate ()
68
-
69
- def time_frame_get_numeric_data (self ):
70
- self .df ._get_numeric_data ()
71
-
72
-
73
58
# ----------------------------------------------------------------------
74
59
# From dict with DatetimeIndex with all offsets
75
60
@@ -84,13 +69,15 @@ def get_period_count(start_date, off):
84
69
if (ten_offsets_in_days == 0 ):
85
70
return 1000
86
71
else :
87
- return min ((9 * ((Timestamp .max - start_date ).days // ten_offsets_in_days )), 1000 )
72
+ periods = 9 * (Timestamp .max - start_date ).days // ten_offsets_in_days
73
+ return min (periods , 1000 )
88
74
89
75
90
76
def get_index_for_offset (off ):
91
77
start_date = Timestamp ('1/1/1900' )
92
- return date_range (start_date , periods = min (1000 , get_period_count (
93
- start_date , off )), freq = off )
78
+ return date_range (start_date ,
79
+ periods = get_period_count (start_date , off ),
80
+ freq = off )
94
81
95
82
96
83
all_offsets = offsets .__all__
@@ -100,21 +87,23 @@ def get_index_for_offset(off):
100
87
all_offsets .extend ([off + '_1' , off + '_2' ])
101
88
102
89
103
- class FrameConstructorDTIndexFromOffsets (object ):
90
+ class FromDictwithTimestampOffsets (object ):
104
91
105
92
params = [all_offsets , [1 , 2 ]]
106
93
param_names = ['offset' , 'n_steps' ]
107
94
108
95
offset_kwargs = {'WeekOfMonth' : {'weekday' : 1 , 'week' : 1 },
109
96
'LastWeekOfMonth' : {'weekday' : 1 , 'week' : 1 },
110
97
'FY5253' : {'startingMonth' : 1 , 'weekday' : 1 },
111
- 'FY5253Quarter' : {'qtr_with_extra_week' : 1 , 'startingMonth' : 1 , 'weekday' : 1 }}
98
+ 'FY5253Quarter' : {'qtr_with_extra_week' : 1 ,
99
+ 'startingMonth' : 1 ,
100
+ 'weekday' : 1 }}
112
101
113
102
offset_extra_cases = {'FY5253' : {'variation' : ['nearest' , 'last' ]},
114
103
'FY5253Quarter' : {'variation' : ['nearest' , 'last' ]}}
115
104
116
105
def setup (self , offset , n_steps ):
117
-
106
+ np . random . seed ( 1234 )
118
107
extra = False
119
108
if offset .endswith ("_" , None , - 1 ):
120
109
extra = int (offset [- 1 ])
@@ -132,7 +121,7 @@ def setup(self, offset, n_steps):
132
121
offset = getattr (offsets , offset )
133
122
self .idx = get_index_for_offset (offset (n_steps , ** kwargs ))
134
123
self .df = DataFrame (np .random .randn (len (self .idx ), 10 ), index = self .idx )
135
- self .d = dict ( self .df .items () )
124
+ self .d = self .df .to_dict ( )
136
125
137
126
def time_frame_ctor (self , offset , n_steps ):
138
127
DataFrame (self .d )
0 commit comments