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

OverflowError: date value out of range in num2date #659

Closed
lyashevska opened this issue May 12, 2017 · 6 comments
Closed

OverflowError: date value out of range in num2date #659

lyashevska opened this issue May 12, 2017 · 6 comments

Comments

@lyashevska
Copy link

Hi,

I am trying to convert this object using num2date. However I get OverflowError: date value out of range
What could possibly cause this behaviour and how it can be fixed. Thanks.

<type 'netCDF4._netCDF4.Variable'>
float64 time(time)
units: days since 1800-01-01 00:00:0.0
long_name: Time
actual_range: [-657073. -656739.]
delta_t: 0000-01-00 00:00:00
avg_period: 0030-00-00 00:00:00
prev_avg_period: 0000-00-07 00:00:00
ltm_range: [ 58804. 69730.]
standard_name: time
axis: T
unlimited dimensions: time
current shape = (12,)
filling off

times = f.variables['time']

times[:]
array([-657073., -657042., -657014., -656983., -656953., -656922.,
-656892., -656861., -656830., -656800., -656769., -656739.])

times.units
u'days since 1800-01-01 00:00:0.0'

netCDF4.version
'1.2.7'

@jswhit
Copy link
Collaborator

jswhit commented May 12, 2017

num2date can't handle dates before 0001-01-01. The first element in your times array (-657073) is before that date using the standard (mixed Julian/Gregorian) calendar. It works if you used 'calendar = Julian' since the first date is 1-01-12 00:00:00. What calendar did you intend to use?

@jswhit
Copy link
Collaborator

jswhit commented May 12, 2017

Stand by - I think this may actually be a bug in how negative times are treated (I don't think the correct date is before 0001-01-01).

@jswhit
Copy link
Collaborator

jswhit commented May 12, 2017

fix in pull request #660

Can you confirm that the correct date for -657073 is 0001-01-01?

@jswhit
Copy link
Collaborator

jswhit commented May 12, 2017

Just checked using https://erddap.marine.ie/erddap/convert/time.html?n=-657073&units=days+since+1800-01-01T00%3A00%3A00Z and this is correct. I'll merge this tomorrow if there are no comments.

jswhit added a commit that referenced this issue May 13, 2017
fix for issue #659 (datetime used when it shouldn't be for negative times)
@lyashevska
Copy link
Author

Thank you for your prompt response. Please go ahead with the merge. I do not have any comments.

@PearlW1
Copy link

PearlW1 commented Sep 11, 2019

if your start_date is '2019-09-08' and end_date is '2019-09-01' ,then use those date in computition, the error "OverflowError: date value out of range in num2date " will be appeared.
how to solve this question?
let start_date is '2019-09-01' and end_date is '2019-09-08', this setting will work.

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

No branches or pull requests

3 participants