@@ -131,128 +131,131 @@ def test_to_records_with_categorical(self):
131131 [
132132 # No dtypes --> default to array dtypes.
133133 (
134- dict () ,
134+ {} ,
135135 np .rec .array (
136136 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
137137 dtype = [("index" , "<i8" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
138138 ),
139139 ),
140140 # Should have no effect in this case.
141141 (
142- dict ( index = True ) ,
142+ { " index" : True } ,
143143 np .rec .array (
144144 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
145145 dtype = [("index" , "<i8" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
146146 ),
147147 ),
148148 # Column dtype applied across the board. Index unaffected.
149149 (
150- dict ( column_dtypes = " <U4") ,
150+ { " column_dtypes" : " <U4"} ,
151151 np .rec .array (
152152 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
153153 dtype = [("index" , "<i8" ), ("A" , "<U4" ), ("B" , "<U4" ), ("C" , "<U4" )],
154154 ),
155155 ),
156156 # Index dtype applied across the board. Columns unaffected.
157157 (
158- dict ( index_dtypes = " <U1") ,
158+ { " index_dtypes" : " <U1"} ,
159159 np .rec .array (
160160 [("0" , 1 , 0.2 , "a" ), ("1" , 2 , 1.5 , "bc" )],
161161 dtype = [("index" , "<U1" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
162162 ),
163163 ),
164164 # Pass in a type instance.
165165 (
166- dict ( column_dtypes = str ) ,
166+ { " column_dtypes" : str } ,
167167 np .rec .array (
168168 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
169169 dtype = [("index" , "<i8" ), ("A" , "<U" ), ("B" , "<U" ), ("C" , "<U" )],
170170 ),
171171 ),
172172 # Pass in a dtype instance.
173173 (
174- dict ( column_dtypes = np .dtype ("unicode" )) ,
174+ { " column_dtypes" : np .dtype ("unicode" )} ,
175175 np .rec .array (
176176 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
177177 dtype = [("index" , "<i8" ), ("A" , "<U" ), ("B" , "<U" ), ("C" , "<U" )],
178178 ),
179179 ),
180180 # Pass in a dictionary (name-only).
181181 (
182- dict ( column_dtypes = {"A" : np .int8 , "B" : np .float32 , "C" : "<U2" }) ,
182+ { " column_dtypes" : {"A" : np .int8 , "B" : np .float32 , "C" : "<U2" }} ,
183183 np .rec .array (
184184 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
185185 dtype = [("index" , "<i8" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "<U2" )],
186186 ),
187187 ),
188188 # Pass in a dictionary (indices-only).
189189 (
190- dict ( index_dtypes = {0 : "int16" }) ,
190+ { " index_dtypes" : {0 : "int16" }} ,
191191 np .rec .array (
192192 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
193193 dtype = [("index" , "i2" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
194194 ),
195195 ),
196196 # Ignore index mappings if index is not True.
197197 (
198- dict ( index = False , index_dtypes = " <U2") ,
198+ { " index" : False , " index_dtypes" : " <U2"} ,
199199 np .rec .array (
200200 [(1 , 0.2 , "a" ), (2 , 1.5 , "bc" )],
201201 dtype = [("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
202202 ),
203203 ),
204204 # Non-existent names / indices in mapping should not error.
205205 (
206- dict ( index_dtypes = {0 : "int16" , "not-there" : "float32" }) ,
206+ { " index_dtypes" : {0 : "int16" , "not-there" : "float32" }} ,
207207 np .rec .array (
208208 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
209209 dtype = [("index" , "i2" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
210210 ),
211211 ),
212212 # Names / indices not in mapping default to array dtype.
213213 (
214- dict ( column_dtypes = {"A" : np .int8 , "B" : np .float32 }) ,
214+ { " column_dtypes" : {"A" : np .int8 , "B" : np .float32 }} ,
215215 np .rec .array (
216216 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
217217 dtype = [("index" , "<i8" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "O" )],
218218 ),
219219 ),
220220 # Names / indices not in dtype mapping default to array dtype.
221221 (
222- dict ( column_dtypes = {"A" : np .dtype ("int8" ), "B" : np .dtype ("float32" )}) ,
222+ { " column_dtypes" : {"A" : np .dtype ("int8" ), "B" : np .dtype ("float32" )}} ,
223223 np .rec .array (
224224 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
225225 dtype = [("index" , "<i8" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "O" )],
226226 ),
227227 ),
228228 # Mixture of everything.
229229 (
230- dict (column_dtypes = {"A" : np .int8 , "B" : np .float32 }, index_dtypes = "<U2" ),
230+ {
231+ "column_dtypes" : {"A" : np .int8 , "B" : np .float32 },
232+ "index_dtypes" : "<U2" ,
233+ },
231234 np .rec .array (
232235 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
233236 dtype = [("index" , "<U2" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "O" )],
234237 ),
235238 ),
236239 # Invalid dype values.
237240 (
238- dict ( index = False , column_dtypes = list ()) ,
241+ { " index" : False , " column_dtypes" : list ()} ,
239242 (ValueError , "Invalid dtype \\ [\\ ] specified for column A" ),
240243 ),
241244 (
242- dict ( index = False , column_dtypes = {"A" : "int32" , "B" : 5 }) ,
245+ { " index" : False , " column_dtypes" : {"A" : "int32" , "B" : 5 }} ,
243246 (ValueError , "Invalid dtype 5 specified for column B" ),
244247 ),
245248 # Numpy can't handle EA types, so check error is raised
246249 (
247- dict (
248- index = False ,
249- column_dtypes = {"A" : "int32" , "B" : CategoricalDtype (["a" , "b" ])},
250- ) ,
250+ {
251+ " index" : False ,
252+ " column_dtypes" : {"A" : "int32" , "B" : CategoricalDtype (["a" , "b" ])},
253+ } ,
251254 (ValueError , "Invalid dtype category specified for column B" ),
252255 ),
253256 # Check that bad types raise
254257 (
255- dict ( index = False , column_dtypes = {"A" : "int32" , "B" : "foo" }) ,
258+ { " index" : False , " column_dtypes" : {"A" : "int32" , "B" : "foo" }} ,
256259 (TypeError , "data type [\" ']foo[\" '] not understood" ),
257260 ),
258261 ],
@@ -276,7 +279,7 @@ def test_to_records_dtype(self, kwargs, expected):
276279 DataFrame (
277280 [[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], columns = list ("abc" )
278281 ).set_index (["a" , "b" ]),
279- dict ( column_dtypes = " float64" , index_dtypes = {0 : "int32" , 1 : "int8" }) ,
282+ { " column_dtypes" : " float64" , " index_dtypes" : {0 : "int32" , 1 : "int8" }} ,
280283 np .rec .array (
281284 [(1 , 2 , 3.0 ), (4 , 5 , 6.0 ), (7 , 8 , 9.0 )],
282285 dtype = [("a" , "<i4" ), ("b" , "i1" ), ("c" , "<f8" )],
@@ -290,7 +293,7 @@ def test_to_records_dtype(self, kwargs, expected):
290293 [("a" , "d" ), ("b" , "e" ), ("c" , "f" )]
291294 ),
292295 ),
293- dict ( column_dtypes = {0 : "<U1" , 2 : "float32" }, index_dtypes = " float32") ,
296+ { " column_dtypes" : {0 : "<U1" , 2 : "float32" }, " index_dtypes" : " float32"} ,
294297 np .rec .array (
295298 [(0.0 , "1" , 2 , 3.0 ), (1.0 , "4" , 5 , 6.0 ), (2.0 , "7" , 8 , 9.0 )],
296299 dtype = [
@@ -312,7 +315,7 @@ def test_to_records_dtype(self, kwargs, expected):
312315 [("d" , - 4 ), ("d" , - 5 ), ("f" , - 6 )], names = list ("cd" )
313316 ),
314317 ),
315- dict ( column_dtypes = " float64" , index_dtypes = {0 : "<U2" , 1 : "int8" }) ,
318+ { " column_dtypes" : " float64" , " index_dtypes" : {0 : "<U2" , 1 : "int8" }} ,
316319 np .rec .array (
317320 [
318321 ("d" , - 4 , 1.0 , 2.0 , 3.0 ),
@@ -352,10 +355,10 @@ def keys(self):
352355
353356 df = DataFrame ({"A" : [1 , 2 ], "B" : [0.2 , 1.5 ], "C" : ["a" , "bc" ]})
354357
355- dtype_mappings = dict (
356- column_dtypes = DictLike (** {"A" : np .int8 , "B" : np .float32 }),
357- index_dtypes = "<U2" ,
358- )
358+ dtype_mappings = {
359+ " column_dtypes" : DictLike (** {"A" : np .int8 , "B" : np .float32 }),
360+ " index_dtypes" : "<U2" ,
361+ }
359362
360363 result = df .to_records (** dtype_mappings )
361364 expected = np .rec .array (
0 commit comments