Correct bool to datetime conversion (behaviour based on int/float processing) by gliptak · Pull Request #13176 · pandas-dev/pandas (original) (raw)
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
- closes ERR: better exception for converting bool to datetime with 0.17 #11853
- tests added / passed
- passes
git diff upstream/master | flake8 --diff - whatsnew entry
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of this make a new path for bool detection
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only true for coerce, pls follow the existing patterns
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
Current coverage is 84.12%
@@ master #13176 diff @@
Files 138 138
Lines 50587 50385 -202
Methods 0 0
Messages 0 0
Branches 0 0
- Hits 42593 42383 -210
- Misses 7994 8002 +8
Partials 0 0
Powered by Codecov. Last updated by b4e2d34...e27a444
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use tm.assert_index_equal
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue number as a comment
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
gliptak changed the title
Convert bool to datetime returns NaT Correct bool to datetime conversion (behaviour based on int/float processing)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add some tests where bools are intermixed with valid (and also invalid conversions)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
Would you like to see any other changes? Thanks
1 similar comment
Would you like to see any other changes? Thanks
@gliptak actually I think I steered you wrong here. These should raise if errors='raise' (more informative message though), pass thru for errors='ignore', and become NaT for errors='coerce'.
They should not convert to 0/1 datetimes.
What is the informative message when raise? Also what does pass through mean when ignore? Thanks
# this is what an unconvertible string does
In [1]: pd.to_datetime('foo', errors='raise')
ValueError: Unknown string format
# ignore just passes thru the values
In [2]: pd.to_datetime('foo', errors='ignore')
Out[2]: 'foo'
so a messge like booleans are not convertible to datetimes is prob enough.
@jreback Is this the expected processing?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow the existing pattern for ignore
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to raise TypeError so it kicks out to the object loop
add a test that has something like
pd.to_datetime(['20130101',True])
ok we have another case.
I accidently gave it this (from the original issue)
In [5]: pd.to_datetime(df.bool)
TypeError: object of type 'instancemethod' has no len()
bool is a method! so this hit the else clause. I think need to make that an elif and is_string_object, then have the else fall thru and raise/coerce as needed. (you could even remove the is_bool_object and just do that in the else and in the exception do type(v)