Skip to content

Commit e5d15b2

Browse files
anmyachevjreback
authored andcommitted
New benchmarks for parsing dates with dayfirst=True and format='%d-%m-%Y' (#26360)
1 parent ef7dc2f commit e5d15b2

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

asv_bench/benchmarks/io/csv.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55
import pandas.util.testing as tm
6-
from pandas import DataFrame, Categorical, date_range, read_csv
6+
from pandas import DataFrame, Categorical, date_range, read_csv, to_datetime
77
from pandas.io.parsers import _parser_defaults
88
from io import StringIO
99

@@ -302,7 +302,7 @@ def mem_parser_chunks(self):
302302

303303
class ReadCSVParseSpecialDate(StringIORewind):
304304
params = (['mY', 'mdY', 'hm'],)
305-
params_name = ['value']
305+
param_names = ['value']
306306
objects = {
307307
'mY': '01-2019\n10-2019\n02/2000\n',
308308
'mdY': '12/02/2010\n',
@@ -319,4 +319,29 @@ def time_read_special_date(self, value):
319319
names=['Date'], parse_dates=['Date'])
320320

321321

322+
class ParseDateComparison(StringIORewind):
323+
params = ([False, True],)
324+
param_names = ['cache_dates']
325+
326+
def setup(self, cache_dates):
327+
count_elem = 10000
328+
data = '12-02-2010\n' * count_elem
329+
self.StringIO_input = StringIO(data)
330+
331+
def time_read_csv_dayfirst(self, cache_dates):
332+
read_csv(self.data(self.StringIO_input), sep=',', header=None,
333+
names=['Date'], parse_dates=['Date'], cache_dates=cache_dates,
334+
dayfirst=True)
335+
336+
def time_to_datetime_dayfirst(self, cache_dates):
337+
df = read_csv(self.data(self.StringIO_input),
338+
dtype={'date': str}, names=['date'])
339+
to_datetime(df['date'], cache=cache_dates, dayfirst=True)
340+
341+
def time_to_datetime_format_DD_MM_YYYY(self, cache_dates):
342+
df = read_csv(self.data(self.StringIO_input),
343+
dtype={'date': str}, names=['date'])
344+
to_datetime(df['date'], cache=cache_dates, format='%d-%m-%Y')
345+
346+
322347
from ..pandas_vb_common import setup # noqa: F401

0 commit comments

Comments
 (0)