Skip to content
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

datestr2num of year and month fails on 29th, 30th, and 31st of month #2481

Merged
merged 1 commit into from Jan 9, 2014

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Oct 1, 2013

datestr2num by default uses the current day if year-month data is converted.
This means that on the 29th, 30th or 31st of any month, datestr2num cannot be used to convert February, and on the 31st of any month, a number of other months cannot be converted.
For example, on September 30 I cannot convert monthly data, as February doesn't have 30 days. Conversion of:
datestr2num('2000-02')
Gives an error:
ValueError: day is out of range for month

datestr2num calls dateutil.parser.parse, which by default uses the
current date at 00:00:00 for missing fields. The dateutil function
also can use a "default" argument to change this bahavoir but it is
not available in datestr2num. datestr2num needs a keyword argument to change the day that is used when it is not supplied.

@mdboom
Copy link
Member

mdboom commented Oct 1, 2013

@mbakker7: Is the attached patch what you had in mind? Does it fix your original issue? If so, I'll add a test and merge this.

@mbakker7
Copy link
Author

mbakker7 commented Oct 1, 2013

Just tried it out, and it works great.

Maybe expand a bit in the doc:

  • default : datetime instance
  •    The default date to use when fields are missing in `d`. Example: Conversion of d = '2008-10' will use current day of the month and time 0:00 if default is not specified, and will insert day and time of default otherwise
    

Thanks,
Mark

pelson added a commit that referenced this pull request Jan 9, 2014
datestr2num of year and month fails on 29th, 30th, and 31st of month
@pelson pelson merged commit cac742e into matplotlib:v1.3.x Jan 9, 2014
@mdboom mdboom deleted the datestr2num-fix branch August 7, 2014 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants