Skip to content

BUG: ignore errors for invalid dates in to_datetime() with errors=coerce (#25512) #26561

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

Merged
merged 5 commits into from
Jun 1, 2019

Conversation

nathalier
Copy link
Contributor

@nathalier nathalier commented May 29, 2019

parsing.try_parse_year_month_day() in _attempt_YYYYMMDD() throws not only ValueError but also OverFlowError for incorrect dates. So handling of this error was added.

…as-dev#25512)

parsing.try_parse_year_month_day() in _attempt_YYYYMMDD() throws not only ValueError but also OverFlowError for incorrect dates. So handling of this error was added.
@codecov
Copy link

codecov bot commented May 29, 2019

Codecov Report

Merging #26561 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26561      +/-   ##
==========================================
- Coverage   91.77%   91.76%   -0.01%     
==========================================
  Files         174      174              
  Lines       50649    50649              
==========================================
- Hits        46483    46479       -4     
- Misses       4166     4170       +4
Flag Coverage Δ
#multiple 90.3% <100%> (ø) ⬆️
#single 41.69% <0%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/core/tools/datetimes.py 85.05% <100%> (ø) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93a67db...2d41f2f. Read the comment docs.

@codecov
Copy link

codecov bot commented May 29, 2019

Codecov Report

Merging #26561 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26561      +/-   ##
==========================================
- Coverage   91.77%   91.77%   -0.01%     
==========================================
  Files         174      174              
  Lines       50649    50681      +32     
==========================================
+ Hits        46483    46510      +27     
- Misses       4166     4171       +5
Flag Coverage Δ
#multiple 90.3% <100%> (ø) ⬆️
#single 41.68% <0%> (-0.1%) ⬇️
Impacted Files Coverage Δ
pandas/core/tools/datetimes.py 85.05% <100%> (ø) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97% <0%> (-0.12%) ⬇️
pandas/core/groupby/groupby.py 97.17% <0%> (-0.06%) ⬇️
pandas/core/groupby/__init__.py 100% <0%> (ø) ⬆️
pandas/core/indexes/base.py 96.71% <0%> (ø) ⬆️
pandas/core/base.py 98.19% <0%> (ø) ⬆️
pandas/core/indexes/interval.py 96.2% <0%> (ø) ⬆️
pandas/core/groupby/generic.py 89.08% <0%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93a67db...e32641e. Read the comment docs.

@simonjayhawkins simonjayhawkins added Bug Datetime Datetime data dtype labels May 29, 2019
@simonjayhawkins simonjayhawkins requested a review from mroeschke May 29, 2019 12:05
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can you add a whatnew note, bug fixes, datetimes is good

@@ -83,6 +83,35 @@ def test_to_datetime_format_YYYYMMDD(self, cache):
result = to_datetime(s, format='%Y%m%d', cache=cache)
assert_series_equal(result, expected)

# GH 25512
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make a new test (and _overflow) in the name

def test_to_datetime_format_YYYYMMDD_overflow(self, cache):
# GH 25512
# NaN before strings with invalid date values, errors=coerce
s = Series(['19801222', np.nan, '20010012', '10019999'])
Copy link
Member

Choose a reason for hiding this comment

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

Could you parameterize over these Series inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it what you meant?
Thanks!

@WillAyd WillAyd added this to the 0.25.0 milestone May 30, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm - nice job!

@jreback jreback merged commit 2630a0b into pandas-dev:master Jun 1, 2019
@jreback
Copy link
Contributor

jreback commented Jun 1, 2019

thanks @nathalier very nice.

note that this might close another existing issue or 2, though searching for issues like this are hard

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 does not ignore the error when there is NaN before wrong datetime when format is %Y%m%d
5 participants