Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f2d9eb9
wip
Jan 27, 2023
ab53530
fixup
Jan 27, 2023
c855c4b
update user guide
Jan 27, 2023
389dd71
whatsnew
Jan 27, 2023
2e6fbcb
gh number
MarcoGorelli Jan 27, 2023
fd5e7c6
update user guide;
Jan 27, 2023
1316559
Merge branch 'deprecate-date-parser' of github.com:MarcoGorelli/panda…
Jan 27, 2023
9594c04
whatsnew
Jan 27, 2023
7e43e3d
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Jan 30, 2023
d9f35f9
update whatsnew note with date_format enhancement
Jan 30, 2023
39cd663
Merge branch 'main' into deprecate-date-parser
MarcoGorelli Feb 1, 2023
a23f101
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 2, 2023
5654f91
make example ipython code-block
Feb 2, 2023
532080c
Merge branch 'main' into deprecate-date-parser
MarcoGorelli Feb 2, 2023
4b5cf56
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 2, 2023
f627ece
add tests for date_format
Feb 2, 2023
113c008
Merge branch 'deprecate-date-parser' of github.com:MarcoGorelli/panda…
Feb 2, 2023
0259f93
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 3, 2023
5390aed
wip add this to read_excel too
Feb 3, 2023
66e8f2e
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 7, 2023
f997edd
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 8, 2023
a7d496b
validate within _parser
Feb 8, 2023
5d18cd1
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 8, 2023
4a233d7
minor fixup
Feb 8, 2023
63eff32
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 8, 2023
5737c70
mention other readers in whatsnew, None -> no_default
Feb 8, 2023
ca0db5c
Update v2.0.0.rst
phofl Feb 10, 2023
ab8b537
Merge branch 'main' into deprecate-date-parser
phofl Feb 10, 2023
f1b6940
Merge branch 'main' into deprecate-date-parser
MarcoGorelli Feb 14, 2023
e9ce938
fixup merge conflict resolution
Feb 15, 2023
2a0cafd
Merge remote-tracking branch 'upstream/main' into deprecate-date-parser
Feb 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for date_format
  • Loading branch information
MarcoGorelli committed Feb 2, 2023
commit f627ecedca1f28b9ea39c9c2dc7023c43ebcd71b
47 changes: 38 additions & 9 deletions pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,20 +1533,31 @@ def test_parse_date_fields(all_parsers):


@xfail_pyarrow
def test_parse_date_all_fields(all_parsers):
@pytest.mark.parametrize(
("key", "value", "warn"),
[
(
"date_parser",
lambda x: pd.to_datetime(x, format="%Y %m %d %H %M %S"),
FutureWarning,
),
("date_format", "%Y %m %d %H %M %S", None),
],
)
def test_parse_date_all_fields(all_parsers, key, value, warn):
parser = all_parsers
data = """\
year,month,day,hour,minute,second,a,b
2001,01,05,10,00,0,0.0,10.
2001,01,5,10,0,00,1.,11.
"""
result = parser.read_csv_check_warnings(
FutureWarning,
warn,
"use 'date_format' instead",
StringIO(data),
header=0,
date_parser=lambda x: pd.to_datetime(x, format="%Y %m %d %H %M %S"),
parse_dates={"ymdHMS": [0, 1, 2, 3, 4, 5]},
**{key: value},
)
expected = DataFrame(
[
Expand All @@ -1559,20 +1570,31 @@ def test_parse_date_all_fields(all_parsers):


@xfail_pyarrow
def test_datetime_fractional_seconds(all_parsers):
@pytest.mark.parametrize(
("key", "value", "warn"),
[
(
"date_parser",
lambda x: pd.to_datetime(x, format="%Y %m %d %H %M %S.%f"),
FutureWarning,
),
("date_format", "%Y %m %d %H %M %S.%f", None),
],
)
def test_datetime_fractional_seconds(all_parsers, key, value, warn):
parser = all_parsers
data = """\
year,month,day,hour,minute,second,a,b
2001,01,05,10,00,0.123456,0.0,10.
2001,01,5,10,0,0.500000,1.,11.
"""
result = parser.read_csv_check_warnings(
FutureWarning,
warn,
"use 'date_format' instead",
StringIO(data),
header=0,
date_parser=lambda x: pd.to_datetime(x, format="%Y %m %d %H %M %S.%f"),
parse_dates={"ymdHMS": [0, 1, 2, 3, 4, 5]},
**{key: value},
)
expected = DataFrame(
[
Expand Down Expand Up @@ -2055,7 +2077,14 @@ def test_infer_first_column_as_index(all_parsers):


@skip_pyarrow
def test_replace_nans_before_parsing_dates(all_parsers):
@pytest.mark.parametrize(
("key", "value", "warn"),
[
("date_parser", lambda x: pd.to_datetime(x, format="%Y-%m-%d"), FutureWarning),
("date_format", "%Y-%m-%d", None),
],
)
def test_replace_nans_before_parsing_dates(all_parsers, key, value, warn):
# GH#26203
parser = all_parsers
data = """Test
Expand All @@ -2066,12 +2095,12 @@ def test_replace_nans_before_parsing_dates(all_parsers):
2017-09-09
"""
result = parser.read_csv_check_warnings(
FutureWarning,
warn,
"use 'date_format' instead",
StringIO(data),
na_values={"Test": ["#", "0"]},
parse_dates=["Test"],
date_parser=lambda x: pd.to_datetime(x, format="%Y-%m-%d"),
**{key: value},
)
expected = DataFrame(
{
Expand Down