@@ -3188,10 +3188,16 @@ def test_datetime_tz_custom(self):
3188
3188
# This timestamp is in 2013 in Europe/Paris but is 2012 in UTC
3189
3189
dt = pd .to_datetime (["2013-01-01 00:00:00+01:00" ], utc = True )
3190
3190
# If tz is currently set as utc, we'll see 2012
3191
- assert dt .format (date_format = "%Y-%m-%d__foo__%H:%M:%S" )[0 ] == "2012-12-31__foo__23:00:00"
3191
+ assert (
3192
+ dt .format (date_format = "%Y-%m-%d__foo__%H:%M:%S" )[0 ]
3193
+ == "2012-12-31__foo__23:00:00"
3194
+ )
3192
3195
# If tz is currently set as paris, we'll see 2013
3193
3196
dt = dt .tz_convert ("Europe/Paris" )
3194
- assert dt .format (date_format = "%Y-%m-%d__foo__%H:%M:%S" )[0 ] == "2013-01-01__foo__00:00:00"
3197
+ assert (
3198
+ dt .format (date_format = "%Y-%m-%d__foo__%H:%M:%S" )[0 ]
3199
+ == "2013-01-01__foo__00:00:00"
3200
+ )
3195
3201
3196
3202
def test_date (self ):
3197
3203
formatted = pd .to_datetime ([datetime (2003 , 1 , 1 ), NaT ]).format ()
@@ -3279,12 +3285,15 @@ class TestDatetimeFastFormatter:
3279
3285
kind of date/time objects.
3280
3286
"""
3281
3287
3282
- @pytest .mark .parametrize ("strftime_format" , (
3283
- "%Y-%m-%d %H:%M:%S" ,
3284
- "%Y%%Y" ,
3285
- "%Y{%Y}" ,
3286
- "%Y-%m-%dT%H:%M:%S.%fZ" ,
3287
- ))
3288
+ @pytest .mark .parametrize (
3289
+ "strftime_format" ,
3290
+ (
3291
+ "%Y-%m-%d %H:%M:%S" ,
3292
+ "%Y%%Y" ,
3293
+ "%Y{%Y}" ,
3294
+ "%Y-%m-%dT%H:%M:%S.%fZ" ,
3295
+ ),
3296
+ )
3288
3297
@pytest .mark .parametrize ("new_style" , (False , True ))
3289
3298
def test_fast_strftime_basic (self , strftime_format , new_style ):
3290
3299
"""Test that formatting standard `datetime` objects with our utils works as good as strftime."""
@@ -3297,8 +3306,13 @@ def test_fast_strftime_basic(self, strftime_format, new_style):
3297
3306
3298
3307
# common dict used for formatting
3299
3308
fmt_dct = dict (
3300
- year = dt .year , month = dt .month , day = dt .day , hour = dt .hour ,
3301
- min = dt .minute , sec = dt .second , us = dt .microsecond
3309
+ year = dt .year ,
3310
+ month = dt .month ,
3311
+ day = dt .day ,
3312
+ hour = dt .hour ,
3313
+ min = dt .minute ,
3314
+ sec = dt .second ,
3315
+ us = dt .microsecond ,
3302
3316
)
3303
3317
3304
3318
# get the formatting string
@@ -3315,11 +3329,14 @@ def test_fast_strftime_basic(self, strftime_format, new_style):
3315
3329
res2 = fast_strftime (dt , strftime_format , new_style_fmt = new_style )
3316
3330
assert res2 == res
3317
3331
3318
- @pytest .mark .parametrize ("strftime_format" , (
3319
- "%Y-%m-%d %H:%M:%S" ,
3320
- "%Y %Y" ,
3321
- "%Y-%m-%dT%H:%M:%S.%fZ" ,
3322
- ))
3332
+ @pytest .mark .parametrize (
3333
+ "strftime_format" ,
3334
+ (
3335
+ "%Y-%m-%d %H:%M:%S" ,
3336
+ "%Y %Y" ,
3337
+ "%Y-%m-%dT%H:%M:%S.%fZ" ,
3338
+ ),
3339
+ )
3323
3340
def test_fast_strftime_perf (self , strftime_format ):
3324
3341
"""Test that formatting standard `datetime` objects with our utils is faster than strftime."""
3325
3342
@@ -3332,8 +3349,13 @@ def test_fast_strftime_perf(self, strftime_format):
3332
3349
3333
3350
# Perf comparison: confirm the results in https://stackoverflow.com/a/43495629/7262247
3334
3351
fmt_dct = dict (
3335
- year = dt .year , month = dt .month , day = dt .day , hour = dt .hour ,
3336
- min = dt .minute , sec = dt .second , us = dt .microsecond
3352
+ year = dt .year ,
3353
+ month = dt .month ,
3354
+ day = dt .day ,
3355
+ hour = dt .hour ,
3356
+ min = dt .minute ,
3357
+ sec = dt .second ,
3358
+ us = dt .microsecond ,
3337
3359
)
3338
3360
3339
3361
glob = globals ()
@@ -3350,7 +3372,7 @@ def test_fast_strftime_perf(self, strftime_format):
3350
3372
Timer ("old_style_format % fmt_dct" , globals = glob ).repeat (7 , 1000 )
3351
3373
)
3352
3374
# Out[5]: 0.0030
3353
- assert new_style_best < strftime_best # much better
3375
+ assert new_style_best < strftime_best # much better
3354
3376
assert old_style_best < new_style_best # even better !
3355
3377
3356
3378
def test_bad_strftime_directive (self ):
@@ -3364,21 +3386,31 @@ def test_bad_strftime_directive(self):
3364
3386
# We align with the same behaviour
3365
3387
x .dt .strftime (date_format = "%Y-%M-%D___" )
3366
3388
3367
- @pytest .mark .parametrize ("date_format" , (
3368
- # note: "%Y-%m-%d %H:%M:%S and "%Y-%m-%d %H:%M:%S.%f are always accelerated (hardcoded)
3369
- "%Y-%m-%d__foo__%H:%M:%S" ,
3370
- "%Y %Y" ,
3371
- "%Y-%m-%dT%H:%M:%S.%fZ" ,
3372
- ))
3389
+ @pytest .mark .parametrize (
3390
+ "date_format" ,
3391
+ (
3392
+ # note: "%Y-%m-%d %H:%M:%S and "%Y-%m-%d %H:%M:%S.%f are always accelerated (hardcoded)
3393
+ "%Y-%m-%d__foo__%H:%M:%S" ,
3394
+ "%Y %Y" ,
3395
+ "%Y-%m-%dT%H:%M:%S.%fZ" ,
3396
+ ),
3397
+ )
3373
3398
def test_perf_datetime64_strftime (self , date_format ):
3374
3399
x = Series (date_range ("20130101 09:00:00" , periods = 100 , freq = "min" ))
3375
3400
# res = x.dt.strftime(date_format=date_format)
3376
3401
# slow_res = x.dt.strftime(date_format=date_format, fast_strftime=False)
3377
3402
3378
3403
glob = globals ()
3379
3404
glob .update (locals ())
3380
- fast_best = min (Timer ("x.dt.strftime(date_format=date_format)" , globals = glob ).repeat (3 , 100 ))
3381
- strftime_best = min (Timer ("x.dt.strftime(date_format=date_format, fast_strftime=False)" , globals = glob ).repeat (3 , 100 ))
3405
+ fast_best = min (
3406
+ Timer ("x.dt.strftime(date_format=date_format)" , globals = glob ).repeat (3 , 100 )
3407
+ )
3408
+ strftime_best = min (
3409
+ Timer (
3410
+ "x.dt.strftime(date_format=date_format, fast_strftime=False)" ,
3411
+ globals = glob ,
3412
+ ).repeat (3 , 100 )
3413
+ )
3382
3414
assert fast_best < strftime_best # much better
3383
3415
3384
3416
# How many alternative are worth doing here ?
0 commit comments