@@ -63,10 +63,13 @@ def peakmem_read_json_lines_concat(self, index):
63
63
class ToJSON (BaseIO ):
64
64
65
65
fname = "__test__.json"
66
- params = ["split" , "columns" , "index" ]
67
- param_names = ["orient" ]
66
+ params = [
67
+ ["split" , "columns" , "index" , "values" , "records" ],
68
+ ["df" , "df_date_idx" , "df_td_int_ts" , "df_int_floats" , "df_int_float_str" ],
69
+ ]
70
+ param_names = ["orient" , "frame" ]
68
71
69
- def setup (self , lines_orient ):
72
+ def setup (self , orient , frame ):
70
73
N = 10 ** 5
71
74
ncols = 5
72
75
index = date_range ("20000101" , periods = N , freq = "H" )
@@ -111,34 +114,85 @@ def setup(self, lines_orient):
111
114
index = index ,
112
115
)
113
116
114
- def time_floats_with_int_index (self , orient ):
115
- self . df .to_json (self .fname , orient = orient )
117
+ def time_to_json (self , orient , frame ):
118
+ getattr ( self , frame ) .to_json (self .fname , orient = orient )
116
119
117
- def time_floats_with_dt_index (self , orient ):
118
- self .df_date_idx .to_json (self .fname , orient = orient )
120
+ def mem_to_json (self , orient , frame ):
121
+ getattr (self , frame ).to_json (self .fname , orient = orient )
122
+
123
+ def time_to_json_wide (self , orient , frame ):
124
+ base_df = getattr (self , frame ).copy ()
125
+ df = concat ([base_df .iloc [:100 ]] * 1000 , ignore_index = True , axis = 1 )
126
+ df .to_json (self .fname , orient = orient )
127
+
128
+ def mem_to_json_wide (self , orient , frame ):
129
+ base_df = getattr (self , frame ).copy ()
130
+ df = concat ([base_df .iloc [:100 ]] * 1000 , ignore_index = True , axis = 1 )
131
+ df .to_json (self .fname , orient = orient )
119
132
120
- def time_delta_int_tstamp (self , orient ):
121
- self .df_td_int_ts .to_json (self .fname , orient = orient )
122
133
123
- def time_float_int (self , orient ):
124
- self .df_int_floats .to_json (self .fname , orient = orient )
134
+ class ToJSONLines (BaseIO ):
125
135
126
- def time_float_int_str (self , orient ):
127
- self .df_int_float_str .to_json (self .fname , orient = orient )
136
+ fname = "__test__.json"
137
+
138
+ def setup (self ):
139
+ N = 10 ** 5
140
+ ncols = 5
141
+ index = date_range ("20000101" , periods = N , freq = "H" )
142
+ timedeltas = timedelta_range (start = 1 , periods = N , freq = "s" )
143
+ datetimes = date_range (start = 1 , periods = N , freq = "s" )
144
+ ints = np .random .randint (100000000 , size = N )
145
+ floats = np .random .randn (N )
146
+ strings = tm .makeStringIndex (N )
147
+ self .df = DataFrame (np .random .randn (N , ncols ), index = np .arange (N ))
148
+ self .df_date_idx = DataFrame (np .random .randn (N , ncols ), index = index )
149
+ self .df_td_int_ts = DataFrame (
150
+ {
151
+ "td_1" : timedeltas ,
152
+ "td_2" : timedeltas ,
153
+ "int_1" : ints ,
154
+ "int_2" : ints ,
155
+ "ts_1" : datetimes ,
156
+ "ts_2" : datetimes ,
157
+ },
158
+ index = index ,
159
+ )
160
+ self .df_int_floats = DataFrame (
161
+ {
162
+ "int_1" : ints ,
163
+ "int_2" : ints ,
164
+ "int_3" : ints ,
165
+ "float_1" : floats ,
166
+ "float_2" : floats ,
167
+ "float_3" : floats ,
168
+ },
169
+ index = index ,
170
+ )
171
+ self .df_int_float_str = DataFrame (
172
+ {
173
+ "int_1" : ints ,
174
+ "int_2" : ints ,
175
+ "float_1" : floats ,
176
+ "float_2" : floats ,
177
+ "str_1" : strings ,
178
+ "str_2" : strings ,
179
+ },
180
+ index = index ,
181
+ )
128
182
129
- def time_floats_with_int_idex_lines (self , orient ):
183
+ def time_floats_with_int_idex_lines (self ):
130
184
self .df .to_json (self .fname , orient = "records" , lines = True )
131
185
132
- def time_floats_with_dt_index_lines (self , orient ):
186
+ def time_floats_with_dt_index_lines (self ):
133
187
self .df_date_idx .to_json (self .fname , orient = "records" , lines = True )
134
188
135
- def time_delta_int_tstamp_lines (self , orient ):
189
+ def time_delta_int_tstamp_lines (self ):
136
190
self .df_td_int_ts .to_json (self .fname , orient = "records" , lines = True )
137
191
138
- def time_float_int_lines (self , orient ):
192
+ def time_float_int_lines (self ):
139
193
self .df_int_floats .to_json (self .fname , orient = "records" , lines = True )
140
194
141
- def time_float_int_str_lines (self , orient ):
195
+ def time_float_int_str_lines (self ):
142
196
self .df_int_float_str .to_json (self .fname , orient = "records" , lines = True )
143
197
144
198
0 commit comments