@@ -287,66 +287,70 @@ def test_convert_nested(self, dtc):
287
287
288
288
289
289
class TestPeriodConverter :
290
- def setup_method (self ):
291
- self .pc = converter .PeriodConverter ()
290
+ @pytest .fixture
291
+ def pc (self ):
292
+ return converter .PeriodConverter ()
292
293
294
+ @pytest .fixture
295
+ def axis (self ):
293
296
class Axis :
294
297
pass
295
298
296
- self .axis = Axis ()
297
- self .axis .freq = "D"
299
+ axis = Axis ()
300
+ axis .freq = "D"
301
+ return axis
298
302
299
- def test_convert_accepts_unicode (self ):
300
- r1 = self . pc .convert ("2012-1-1" , None , self . axis )
301
- r2 = self . pc .convert ("2012-1-1" , None , self . axis )
303
+ def test_convert_accepts_unicode (self , pc , axis ):
304
+ r1 = pc .convert ("2012-1-1" , None , axis )
305
+ r2 = pc .convert ("2012-1-1" , None , axis )
302
306
assert r1 == r2
303
307
304
- def test_conversion (self ):
305
- rs = self . pc .convert (["2012-1-1" ], None , self . axis )[0 ]
308
+ def test_conversion (self , pc , axis ):
309
+ rs = pc .convert (["2012-1-1" ], None , axis )[0 ]
306
310
xp = Period ("2012-1-1" ).ordinal
307
311
assert rs == xp
308
312
309
- rs = self . pc .convert ("2012-1-1" , None , self . axis )
313
+ rs = pc .convert ("2012-1-1" , None , axis )
310
314
assert rs == xp
311
315
312
- rs = self . pc .convert ([date (2012 , 1 , 1 )], None , self . axis )[0 ]
316
+ rs = pc .convert ([date (2012 , 1 , 1 )], None , axis )[0 ]
313
317
assert rs == xp
314
318
315
- rs = self . pc .convert (date (2012 , 1 , 1 ), None , self . axis )
319
+ rs = pc .convert (date (2012 , 1 , 1 ), None , axis )
316
320
assert rs == xp
317
321
318
- rs = self . pc .convert ([Timestamp ("2012-1-1" )], None , self . axis )[0 ]
322
+ rs = pc .convert ([Timestamp ("2012-1-1" )], None , axis )[0 ]
319
323
assert rs == xp
320
324
321
- rs = self . pc .convert (Timestamp ("2012-1-1" ), None , self . axis )
325
+ rs = pc .convert (Timestamp ("2012-1-1" ), None , axis )
322
326
assert rs == xp
323
327
324
- rs = self . pc .convert ("2012-01-01" , None , self . axis )
328
+ rs = pc .convert ("2012-01-01" , None , axis )
325
329
assert rs == xp
326
330
327
- rs = self . pc .convert ("2012-01-01 00:00:00+0000" , None , self . axis )
331
+ rs = pc .convert ("2012-01-01 00:00:00+0000" , None , axis )
328
332
assert rs == xp
329
333
330
- rs = self . pc .convert (
334
+ rs = pc .convert (
331
335
np .array (
332
336
["2012-01-01 00:00:00" , "2012-01-02 00:00:00" ],
333
337
dtype = "datetime64[ns]" ,
334
338
),
335
339
None ,
336
- self . axis ,
340
+ axis ,
337
341
)
338
342
assert rs [0 ] == xp
339
343
340
- def test_integer_passthrough (self ):
344
+ def test_integer_passthrough (self , pc , axis ):
341
345
# GH9012
342
- rs = self . pc .convert ([0 , 1 ], None , self . axis )
346
+ rs = pc .convert ([0 , 1 ], None , axis )
343
347
xp = [0 , 1 ]
344
348
assert rs == xp
345
349
346
- def test_convert_nested (self ):
350
+ def test_convert_nested (self , pc , axis ):
347
351
data = ["2012-1-1" , "2012-1-2" ]
348
- r1 = self . pc .convert ([data , data ], None , self . axis )
349
- r2 = [self . pc .convert (data , None , self . axis ) for _ in range (2 )]
352
+ r1 = pc .convert ([data , data ], None , axis )
353
+ r2 = [pc .convert (data , None , axis ) for _ in range (2 )]
350
354
assert r1 == r2
351
355
352
356
0 commit comments