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 }})

@gliptak

jreback

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

jreback

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

@codecov-io

Current coverage is 84.12%

Merging #13176 into master will decrease coverage by <.01%

@@ master #13176 diff @@

Files 138 138
Lines 50587 50385 -202
Methods 0 0
Messages 0 0
Branches 0 0

Powered by Codecov. Last updated by b4e2d34...e27a444

jreback

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

@jreback

jreback

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 gliptak changed the titleConvert bool to datetime returns NaT Correct bool to datetime conversion (behaviour based on int/float processing)

May 14, 2016

@gliptak

@gliptak

jreback

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

@gliptak

Would you like to see any other changes? Thanks

1 similar comment

@gliptak

Would you like to see any other changes? Thanks

@jreback

@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.

@gliptak

What is the informative message when raise? Also what does pass through mean when ignore? Thanks

@jreback

# 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.

@gliptak

@jreback Is this the expected processing?

jreback

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])

@jreback

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)

@gliptak

@gliptak

@gliptak

@jreback

Labels