-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fix TypeError for invalid integer dates %Y%m%d with errors='ignore' #26585
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,25 @@ def test_to_datetime_format_integer(self, cache): | |
result = to_datetime(s, format='%Y%m', cache=cache) | ||
assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize('int_date, expected', [ | ||
# valid date, length == 8 | ||
[20121030, datetime(2012, 10, 30)], | ||
# short valid date, length == 6 | ||
[199934, datetime(1999, 3, 4)], | ||
# long integer date partially parsed to datetime(2012,1,1), length > 8 | ||
[2012010101, 2012010101], | ||
# invalid date partially parsed to datetime(2012,9,9), length == 8 | ||
[20129930, 20129930], | ||
# short integer date partially parsed to datetime(2012,9,9), length < 8 | ||
[2012993, 2012993], | ||
# short invalid date, length == 4 | ||
[2121, 2121]]) | ||
def test_int_to_datetime_format_YYYYMMDD_typeerror(self, int_date, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you try with a too short as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @jreback, Also I found result can be unpredictable for some short dates (either in integer or string format) with length > 4. pd.to_datetime(12912, format="%Y%m%d", errors='ignore')
Out[4]: 12912
pd.to_datetime(21213, format="%Y%m%d", errors='ignore')
Out[5]: datetime.datetime(2, 12, 13, 0, 0) Nevertheless it's not connected to this TypeError. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is weird, these should for sure fail, but maybe going down an odd path. ok can address in another issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
expected): | ||
# GH 26583 | ||
result = to_datetime(int_date, format='%Y%m%d', errors='ignore') | ||
assert result == expected | ||
|
||
@pytest.mark.parametrize('cache', [True, False]) | ||
def test_to_datetime_format_microsecond(self, cache): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind converting these to use
format
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just tried to do it but a couple of tests failed. I don't know the reason yet.