Error handeling in str_to_datetime

User 2568 | 4/30/2016, 11:42:25 PM

I'm using strtodatetime to convert a column in a very large sf from string to datetime. WHen I use it I got the error message

RuntimeError: Runtime Exception. Unable to interpret  as string with %Y-%m-%d format

Due to the formatting, it was not clear to me that the error message included the string it was trying to convert. Perhaps putting the offending string in quotes would have helped, i.e., .

RuntimeError: Runtime Exception. Unable to interpret '' as string with %Y-%m-%d format

Furthermore, I think it would be handy to provide a option for dealing with errors, as is done with some other routines. I'm thinking some thing like

missing_value_action : [str, datetime.datetime], optional
      Action to perform when string does not fit the pattern. Can be one of:

		'datetime': Fill using this datetime object
		‘impute’: Fill in with the mean of the preceding and following dates [useful for time series like data].
		‘error’: Do not proceed with evaluation and terminate with an error message.

Comments

User 16 | 5/2/2016, 5:46:19 PM

@Kevin_McIsaac - Thanks for your feedback. I've opened an internal issue.


User 2568 | 5/7/2016, 1:48:18 AM

I found a simple solution for my problem. When I read the data from a cvs file, I set navalues=''. When an emplty date strings is read it is stored as None rather than ''. Now when I use sf['date'].strto_datetime(....) this ignores Null entries.

I'm also very impressed how quickly this conversion work. I have 35 rows and its quick. The bottleneck now is imputing missing dates, but that's not too bad.