Skip to content

New benchmarks for parsing dates with dayfirst=True and format='%d-%m-%Y' #26360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions asv_bench/benchmarks/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand All @@ -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