2
timestamp = []
for d, t in zip(data['Date'], data['Time']):
    try:
        ts = datetime.datetime.strptime(d+' '+t, '%m/%d/%Y %H:%M:%S')
        timestamp.append(time.mktime(ts.timetuple()))
    except ValueError:
        # print('ValueError')
        timestamp.append('ValueError')

ERROR : OverflowError: mktime argument out of range

this is from code earthquake prediction using machine learning

Reti43
  • 9,656
  • 3
  • 28
  • 44
  • What kind of computer are you writing this on? Linux, Mac, Windows? – Ollie in PGH Apr 05 '21 at 12:19
  • 2
    Welcome to SO. Please take a moment to the read the [FAQ](https://stackoverflow.com/help/asking) for asking questions. I searched for another [question](https://stackoverflow.com/questions/2518706/python-mktime-overflow-error) with a similar error and I found your question there posted as an answer. Didn't the answers there resolve your problem? You should also provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with any necessary values hardcoded. And please show some effort in learning how to both use the site and ask a good question. – Reti43 Apr 05 '21 at 12:19
  • 2
    Does this answer your question? [Python | mktime overflow error](https://stackoverflow.com/questions/2518706/python-mktime-overflow-error) – Reti43 Apr 05 '21 at 12:53
  • @Reti43 I think they answered it, it's a windows specific error due to the epoch limitations. I assume he's using a date prior to 1970. – NationWidePants Apr 05 '21 at 12:58
  • In general, this seems like a rather obfuscated way to get Unix time. datetime objects have a `timestamp()` method since a while now. – FObersteiner Apr 05 '21 at 13:23

1 Answers1

0

I wanted to prove the issue is reproducible: I will add to this if I find a solution.

import time, datetime
d = '04/04/1000'
t = '12:40:00'
dj = d + ' ' + t
ts = datetime.datetime.strptime(dj, '%m/%d/%Y %H:%M:%S')
time.mktime(ts.timetuple())
NationWidePants
  • 447
  • 8
  • 33
  • That this error can be reproduced is not even debatable. I've even linked another question in the comments which explains how and why (which the OP is even aware of himself). But he hasn't provided us with the values he used, even though it's still extremely likely they were out of range, as the error itself so explicitly states. – Reti43 Apr 05 '21 at 12:57
  • @Reti43 True, you did answer it, which is why I agreed with you, but comments can't take formatted code; a limitation of this platform. Personally I think they should take markdown in the comments. – NationWidePants Apr 05 '21 at 12:59
  • @Reti43 your first complaint about this post was that it didn't provide reproducible code. – NationWidePants Apr 05 '21 at 13:01
  • That is correct. And all you've done is give some values to `d` and `t`. Which is exactly what my comment was nudging the OP to do. One can argue whether a definite input was necessary given how clear his error was, but it was not a complaint however you look at it. – Reti43 Apr 05 '21 at 13:04
  • @Reti43 I figure providing an example would give chance for growth, but that can be argued. I don't disagree with your position. – NationWidePants Apr 05 '21 at 13:07