diff --git a/asv_bench/benchmarks/io/csv.py b/asv_bench/benchmarks/io/csv.py index c51fb09ad8671..a12e603a6017f 100644 --- a/asv_bench/benchmarks/io/csv.py +++ b/asv_bench/benchmarks/io/csv.py @@ -3,7 +3,7 @@ import numpy as np import pandas.util.testing as tm -from pandas import DataFrame, Categorical, date_range, read_csv +from pandas import DataFrame, Categorical, date_range, read_csv, to_datetime from pandas.io.parsers import _parser_defaults from io import StringIO @@ -273,7 +273,7 @@ def mem_parser_chunks(self): class ReadCSVParseSpecialDate(StringIORewind): params = (['mY', 'mdY', 'hm'],) - params_name = ['value'] + param_names = ['value'] objects = { 'mY': '01-2019\n10-2019\n02/2000\n', 'mdY': '12/02/2010\n', @@ -290,4 +290,29 @@ def time_read_special_date(self, value): names=['Date'], parse_dates=['Date']) +class ParseDateComparison(StringIORewind): + params = ([False, True],) + param_names = ['cache_dates'] + + def setup(self, cache_dates): + count_elem = 10000 + data = '12-02-2010\n' * count_elem + self.StringIO_input = StringIO(data) + + def time_read_csv_dayfirst(self, cache_dates): + read_csv(self.data(self.StringIO_input), sep=',', header=None, + names=['Date'], parse_dates=['Date'], cache_dates=cache_dates, + dayfirst=True) + + def time_to_datetime_dayfirst(self, cache_dates): + df = read_csv(self.data(self.StringIO_input), + dtype={'date': str}, names=['date']) + to_datetime(df['date'], cache=cache_dates, dayfirst=True) + + def time_to_datetime_format_DD_MM_YYYY(self, cache_dates): + df = read_csv(self.data(self.StringIO_input), + dtype={'date': str}, names=['date']) + to_datetime(df['date'], cache=cache_dates, format='%d-%m-%Y') + + from ..pandas_vb_common import setup # noqa: F401