From b096c81588dadddfeee38445aaf24a88b2a0f871 Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Thu, 6 Sep 2012 20:54:48 +0100 Subject: [PATCH 1/2] Add dateutil kwargs to csv2rec Fixes ambiguous date problems between US/UK date conventions. --- lib/matplotlib/mlab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index 274023c8ccc2..5b3fd8f8d354 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -2090,7 +2090,7 @@ def extract(r): def csv2rec(fname, comments='#', skiprows=0, checkrows=0, delimiter=',', converterd=None, names=None, missing='', missingd=None, - use_mrecords=False): + use_mrecords=False, dayfirst=False, yearfirst=False): """ Load data from comma/space/tab delimited file in *fname* into a numpy record array and return the record array. @@ -2216,7 +2216,7 @@ def mybool(x): def mydate(x): # try and return a date object - d = dateparser(x) + d = dateparser(x, dayfirst=dayfirst, yearfirst=yearfirst) if d.hour>0 or d.minute>0 or d.second>0: raise ValueError('not a date') From 227c10b908222a55ef71af6c3225667b9ee627f0 Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Sat, 30 Mar 2013 23:30:17 -0500 Subject: [PATCH 2/2] Add documentation for new csv2rec dateutil kwwargs --- lib/matplotlib/mlab.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index 5b3fd8f8d354..dfcddca18717 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -2129,6 +2129,14 @@ def csv2rec(fname, comments='#', skiprows=0, checkrows=0, delimiter=',', - *use_mrecords*: if True, return an mrecords.fromrecords record array if any of the data are missing + - *dayfirst*: default is False so that MM-DD-YY has precedence over + DD-MM-YY. See http://labix.org/python-dateutil#head-b95ce2094d189a89f80f5ae52a05b4ab7b41af47 + for further information. + + - *yearfirst*: default is False so that MM-DD-YY has precedence over + YY-MM-DD. See http://labix.org/python-dateutil#head-b95ce2094d189a89f80f5ae52a05b4ab7b41af47 + for further information. + If no rows are found, *None* is returned -- see :file:`examples/loadrec.py` """