2
2
3
3
from .pandas_vb_common import *
4
4
import scipy .sparse
5
- from pandas import SparseSeries , SparseDataFrame
5
+ from pandas import SparseSeries , SparseDataFrame , SparseArray
6
6
7
7
8
8
class sparse_series_to_frame (object ):
@@ -23,6 +23,69 @@ def time_sparse_series_to_frame(self):
23
23
SparseDataFrame (self .series )
24
24
25
25
26
+ class sparse_array_constructor (object ):
27
+ goal_time = 0.2
28
+
29
+ def setup (self ):
30
+ np .random .seed (1 )
31
+ self .int64_10percent = self .make_numeric_array (length = 1000000 , dense_size = 100000 , fill_value = 0 , dtype = np .int64 )
32
+ self .int64_1percent = self .make_numeric_array (length = 1000000 , dense_size = 10000 , fill_value = 0 , dtype = np .int64 )
33
+
34
+ self .float64_10percent = self .make_numeric_array (length = 1000000 , dense_size = 100000 , fill_value = np .nan , dtype = np .float64 )
35
+ self .float64_1percent = self .make_numeric_array (length = 1000000 , dense_size = 10000 , fill_value = np .nan , dtype = np .float64 )
36
+
37
+ self .object_nan_fill_value_10percent = self .make_object_array (length = 1000000 , dense_size = 100000 , fill_value = np .nan )
38
+ self .object_nan_fill_value_1percent = self .make_object_array (length = 1000000 , dense_size = 10000 , fill_value = np .nan )
39
+
40
+ self .object_non_nan_fill_value_10percent = self .make_object_array (length = 1000000 , dense_size = 100000 , fill_value = 0 )
41
+ self .object_non_nan_fill_value_1percent = self .make_object_array (length = 1000000 , dense_size = 10000 , fill_value = 0 )
42
+
43
+ def make_numeric_array (self , length , dense_size , fill_value , dtype ):
44
+ arr = np .array ([fill_value ] * length , dtype = dtype )
45
+ indexer = np .unique (np .random .randint (0 , length , dense_size ))
46
+ arr [indexer ] = np .random .randint (0 , 100 , len (indexer ))
47
+ return (arr , fill_value , dtype )
48
+
49
+ def make_object_array (self , length , dense_size , fill_value ):
50
+ elems = np .array (['a' , 0.0 , False , 1 , 2 ], dtype = np .object )
51
+ arr = np .array ([fill_value ] * length , dtype = np .object )
52
+ indexer = np .unique (np .random .randint (0 , length , dense_size ))
53
+ arr [indexer ] = np .random .choice (elems , len (indexer ))
54
+ return (arr , fill_value , np .object )
55
+
56
+ def time_sparse_array_constructor_int64_10percent (self ):
57
+ arr , fill_value , dtype = self .int64_10percent
58
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
59
+
60
+ def time_sparse_array_constructor_int64_1percent (self ):
61
+ arr , fill_value , dtype = self .int64_1percent
62
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
63
+
64
+ def time_sparse_array_constructor_float64_10percent (self ):
65
+ arr , fill_value , dtype = self .float64_10percent
66
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
67
+
68
+ def time_sparse_array_constructor_float64_1percent (self ):
69
+ arr , fill_value , dtype = self .float64_1percent
70
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
71
+
72
+ def time_sparse_array_constructor_object_nan_fill_value_10percent (self ):
73
+ arr , fill_value , dtype = self .object_nan_fill_value_10percent
74
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
75
+
76
+ def time_sparse_array_constructor_object_nan_fill_value_1percent (self ):
77
+ arr , fill_value , dtype = self .object_nan_fill_value_1percent
78
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
79
+
80
+ def time_sparse_array_constructor_object_non_nan_fill_value_10percent (self ):
81
+ arr , fill_value , dtype = self .object_non_nan_fill_value_10percent
82
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
83
+
84
+ def time_sparse_array_constructor_object_non_nan_fill_value_1percent (self ):
85
+ arr , fill_value , dtype = self .object_non_nan_fill_value_1percent
86
+ SparseArray (arr , fill_value = fill_value , dtype = dtype )
87
+
88
+
26
89
class sparse_frame_constructor (object ):
27
90
goal_time = 0.2
28
91
0 commit comments