Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4281f16
DEPR: Deprecate parse_date_time in pandas.io.date_converters and upda…
avinashpancham Aug 15, 2020
852d4d9
DEPR: Deprecate parse_date_fields in pandas.io.date_converters and up…
avinashpancham Aug 15, 2020
eed8f16
DEPR: Deprecate parse_all_fields in pandas.io.date_converters and upd…
avinashpancham Aug 15, 2020
65ec570
DEPR: Deprecate generic_parser in pandas.io.date_converters
avinashpancham Aug 15, 2020
344e5de
DOC: Update docstrings
avinashpancham Aug 15, 2020
04d3416
DOC: remove mentions of the generic_parser functionality in the docum…
avinashpancham Aug 15, 2020
3df6bf9
CLN: remove date_parser argument from test where it is not necessary
avinashpancham Aug 15, 2020
c995111
TYP: Add MutableMapping to type hinting for pd.to_datetime
avinashpancham Aug 15, 2020
ef02e73
ENH: Add overloading to pd.to_datetime for MutableMapping
avinashpancham Aug 15, 2020
3376f49
TST: Update tests where generic_parser is used
avinashpancham Aug 18, 2020
71297cf
TST: Update tests for generic_parser in line with pandas styleguide
avinashpancham Aug 18, 2020
a4a3203
Assert warnings in test_parse_dates.py instead of filtering warnings
avinashpancham Aug 20, 2020
8d970ca
Update deprecated version and remove double doc string text
avinashpancham Aug 25, 2020
2033dc3
Revert to the old implementation of the date_converters function and …
avinashpancham Aug 25, 2020
8f90441
Remove superfluous noqa statement
avinashpancham Aug 26, 2020
2a2a271
Only assert warnings for lines that produce a warning
avinashpancham Aug 26, 2020
427bbf0
Add pytest parametrize to test old and new dateparser function
avinashpancham Aug 29, 2020
b4ed5be
Merge branch 'master' of https://github.com/pandas-dev/pandas into de…
avinashpancham Sep 5, 2020
2d80bdc
Add whatsnew entry
avinashpancham Sep 6, 2020
1458bc7
Update references in whatsnew message
avinashpancham Sep 12, 2020
a33a604
Merge remote-tracking branch 'upstream/master' into deprecate_date_co…
avinashpancham Sep 12, 2020
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
DEPR: Deprecate parse_all_fields in pandas.io.date_converters and upd…
…ate tests
  • Loading branch information
avinashpancham committed Aug 15, 2020
commit eed8f16b54f873f84007104abd4c76f62d2416eb
45 changes: 35 additions & 10 deletions pandas/io/date_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import numpy as np

from pandas._libs.tslibs import parsing

from pandas import to_datetime


Expand Down Expand Up @@ -51,16 +49,43 @@ def parse_date_fields(year_col, month_col, day_col):


def parse_all_fields(year_col, month_col, day_col, hour_col, minute_col, second_col):
year_col = _maybe_cast(year_col)
month_col = _maybe_cast(month_col)
day_col = _maybe_cast(day_col)
hour_col = _maybe_cast(hour_col)
minute_col = _maybe_cast(minute_col)
second_col = _maybe_cast(second_col)
return parsing.try_parse_datetime_components(
year_col, month_col, day_col, hour_col, minute_col, second_col
"""Convert separate columns with years, months, days, hours, minutes and seconds
into a single datetime column

.. deprecated:: 1.1.0
Use pd.to_datetime({"year": year_col, "month": month_col, "day": day_col,
"hour": hour_col, "minute": minute_col, second": second_col}) instead to get
a Pandas Series.
Use ser = pd.to_datetime({"year": year_col, "month": month_col, "day": day_col,
"hour": hour_col, "minute": minute_col, second": second_col}) and
np.array([s.to_pydatetime() for s in ser]) instead to get a Numpy array.
"""

warnings.warn(
"""
Use pd.to_datetime({"year": year_col, "month": month_col, "day": day_col,
"hour": hour_col, "minute": minute_col, second": second_col}) instead to get a Pandas Series.
Use ser = pd.to_datetime({"year": year_col, "month": month_col, "day": day_col,
"hour": hour_col, "minute": minute_col, second": second_col}) and
np.array([s.to_pydatetime() for s in ser]) instead to get a Numpy array.
""", # noqa: E501
FutureWarning,
stacklevel=2,
)

ser = to_datetime(
{
"year": year_col,
"month": month_col,
"day": day_col,
"hour": hour_col,
"minute": minute_col,
"second": second_col,
}
)

return np.array([s.to_pydatetime() for s in ser])


def generic_parser(parse_func, *cols):
N = _check_columns(cols)
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import pandas._testing as tm
from pandas.core.indexes.datetimes import date_range

import pandas.io.date_converters as conv

# constant
_DEFAULT_DATETIME = datetime(1, 1, 1)

Expand Down Expand Up @@ -1290,6 +1288,7 @@ def test_parse_date_fields(all_parsers):


def test_parse_date_all_fields(all_parsers):

parser = all_parsers
data = """\
year,month,day,hour,minute,second,a,b
Expand All @@ -1299,7 +1298,7 @@ def test_parse_date_all_fields(all_parsers):
result = parser.read_csv(
StringIO(data),
header=0,
date_parser=conv.parse_all_fields,
date_parser=lambda x: pd.to_datetime(x, format="%Y %m %d %H %M %S"),
parse_dates={"ymdHMS": [0, 1, 2, 3, 4, 5]},
)
expected = DataFrame(
Expand All @@ -1322,7 +1321,8 @@ def test_datetime_fractional_seconds(all_parsers):
result = parser.read_csv(
StringIO(data),
header=0,
date_parser=conv.parse_all_fields,
# date_parser=conv.parse_all_fields,
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]},
)
expected = DataFrame(
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/io/test_date_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def test_parse_all_fields():
days = np.array([3, 4])
years = np.array([2007, 2008])
months = np.array([1, 2])

result = conv.parse_all_fields(years, months, days, hours, minutes, seconds)
expected = np.array([datetime(2007, 1, 3, 5, 7, 9), datetime(2008, 2, 4, 6, 8, 0)])
tm.assert_numpy_array_equal(result, expected)

with tm.assert_produces_warning(FutureWarning):
result = conv.parse_all_fields(years, months, days, hours, minutes, seconds)
tm.assert_numpy_array_equal(result, expected)