@@ -76,6 +76,54 @@ def time_frame(self, obs):
76
76
self .data .to_csv (self .fname )
77
77
78
78
79
+ class ToCSVIndexes (BaseIO ):
80
+
81
+ fname = "__test__.csv"
82
+
83
+ @staticmethod
84
+ def _create_df (rows , cols ):
85
+ index_cols = {
86
+ "index1" : np .random .randint (0 , rows , rows ),
87
+ "index2" : np .full (rows , 1 , dtype = np .int ),
88
+ "index3" : np .full (rows , 1 , dtype = np .int ),
89
+ }
90
+ data_cols = {
91
+ f"col{ i } " : np .random .uniform (0 , 100000.0 , rows ) for i in range (cols )
92
+ }
93
+ df = DataFrame ({** index_cols , ** data_cols })
94
+ return df
95
+
96
+ def setup (self ):
97
+ ROWS = 100000
98
+ COLS = 5
99
+ # For tests using .head(), create an initial dataframe with this many times
100
+ # more rows
101
+ HEAD_ROW_MULTIPLIER = 10
102
+
103
+ self .df_standard_index = self ._create_df (ROWS , COLS )
104
+
105
+ self .df_custom_index_then_head = (
106
+ self ._create_df (ROWS * HEAD_ROW_MULTIPLIER , COLS )
107
+ .set_index (["index1" , "index2" , "index3" ])
108
+ .head (ROWS )
109
+ )
110
+
111
+ self .df_head_then_custom_index = (
112
+ self ._create_df (ROWS * HEAD_ROW_MULTIPLIER , COLS )
113
+ .head (ROWS )
114
+ .set_index (["index1" , "index2" , "index3" ])
115
+ )
116
+
117
+ def time_standard_index (self ):
118
+ self .df_standard_index .to_csv (self .fname )
119
+
120
+ def time_multiindex (self ):
121
+ self .df_head_then_custom_index .to_csv (self .fname )
122
+
123
+ def time_head_of_multiindex (self ):
124
+ self .df_custom_index_then_head .to_csv (self .fname )
125
+
126
+
79
127
class StringIORewind :
80
128
def data (self , stringio_object ):
81
129
stringio_object .seek (0 )
0 commit comments