Skip to content

add try / except to address issue #10154 to_datetime, Inconsistent be… #10216

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

Closed
wants to merge 15 commits into from
Closed

Conversation

vincentdavis
Copy link
Contributor

closes #10154 to_datetime, Inconsistent behavior with invalid dates.

results are now

In [2]: pd.to_datetime('2015-02-29', format="%Y-%m-%d", coerce=True)
Out[2]: NaT

In [3]: pd.to_datetime('2015-03-32', format="%Y-%m-%d", coerce=True)
Out[3]: NaT

In [4]: pd.to_datetime('2015-02-32', format="%Y-%m-%d", coerce=True)
Out[4]: NaT

In [5]: pd.to_datetime('2015-04-31', format="%Y-%m-%d", coerce=True)
Out[5]: NaT

@jreback
Copy link
Contributor

jreback commented May 27, 2015

needs tests

@jreback jreback added Bug Datetime Datetime data dtype labels May 27, 2015
@jreback jreback added this to the 0.17.0 milestone May 27, 2015
@@ -737,6 +737,13 @@ def test_get_period_field_raises_on_out_of_range(self):
def test_get_period_field_array_raises_on_out_of_range(self):
self.assertRaises(ValueError, period.get_period_field_arr, -1, np.empty(1), 0)

class TestDaysInMonth(tm.TestCase):
def test_day_not_in_month_coerce_true(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add the issue number as a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I did, not sure what went wrong.

self.assertTrue(isnull(to_datetime('2015-02-32', format="%Y-%m-%d", coerce=True)))
self.assertTrue(isnull(to_datetime('2015-04-31', format="%Y-%m-%d", coerce=True)))
def test_day_not_in_month_coerce_false(self):
self.assertRaises(ValueError, to_datetime, '2015-02-29', format="%Y-%m-%d", coerce=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh, test both errors='ignore' and errors='raise' here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct

In [10]: pd.to_datetime('2015-02-29', errors='ignore',  coerce=False)
Out[10]: '2015-02-29'

I would expect the same from this but get a ValueError.

In [12]: pd.to_datetime('2015-02-29', errors='ignore', format="%Y-%m-%d", coerce=False)
....
ValueError: day is out of range for month

adding format="%Y-%m-%d" should not change the output.
Is this correct and also needs to be fixed?

@jreback
Copy link
Contributor

jreback commented Jun 26, 2015

can you rebase

@vincentdavis
Copy link
Contributor Author

On Fri, Jun 26, 2015 at 5:39 PM, jreback [email protected] wrote:

can you rebase

I will work on that this weekend.

vincentdavis and others added 12 commits June 26, 2015 20:51
update pymysql to 0.6.3 to avoid cursor bugs

Add documentation and tests for SQLAlchemy connectables

explicit reference to connection/engine in docs

Temporary table test

pass compile the connectable
Updated the docstring to make clear that a HDFStore is required for a buffer, if a path is not directly passed
support both sqlalchemy engines and connections
Updated to_hdf doc string
TST: DataFrame.quantile should have Float64Index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_datetime, inconsistent behavior with invalid dates.
4 participants