Skip to content

Commit

Permalink
DEP: Enforce deprecation of date converters for csv (pandas-dev#49086)
Browse files Browse the repository at this point in the history
* DEP: Enforce deprecation of date converters for csv

* Add whatsnew

* Add check
  • Loading branch information
phofl authored and noatamir committed Nov 9, 2022
1 parent 80bdd41 commit 28405d8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 311 deletions.
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ Deprecations

Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Removed Date parser functions :func:`~pandas.io.date_converters.parse_date_time`,
:func:`~pandas.io.date_converters.parse_date_fields`, :func:`~pandas.io.date_converters.parse_all_fields`
and :func:`~pandas.io.date_converters.generic_parser` (:issue:`24518`)
- Remove argument ``squeeze`` from :meth:`DataFrame.groupby` and :meth:`Series.groupby` (:issue:`32380`)
- Removed ``keep_tz`` argument in :meth:`DatetimeIndex.to_series` (:issue:`29731`)
- Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`)
Expand Down
8 changes: 0 additions & 8 deletions pandas/_libs/tslibs/parsing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ def try_parse_dates(
dayfirst: bool = ...,
default: datetime | None = ...,
) -> npt.NDArray[np.object_]: ...
def try_parse_date_and_time(
dates: npt.NDArray[np.object_], # object[:]
times: npt.NDArray[np.object_], # object[:]
date_parser=...,
time_parser=...,
dayfirst: bool = ...,
default: datetime | None = ...,
) -> npt.NDArray[np.object_]: ...
def try_parse_year_month_day(
years: npt.NDArray[np.object_], # object[:]
months: npt.NDArray[np.object_], # object[:]
Expand Down
43 changes: 0 additions & 43 deletions pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -741,49 +741,6 @@ def try_parse_dates(
return result.base # .base to access underlying ndarray


def try_parse_date_and_time(
object[:] dates,
object[:] times,
date_parser=None,
time_parser=None,
bint dayfirst=False,
default=None,
) -> np.ndarray:
cdef:
Py_ssize_t i, n
object[::1] result

n = len(dates)
# TODO(cython3): Use len instead of `shape[0]`
if times.shape[0] != n:
raise ValueError('Length of dates and times must be equal')
result = np.empty(n, dtype='O')

if date_parser is None:
if default is None: # GH2618
date = datetime.now()
default = datetime(date.year, date.month, 1)

parse_date = lambda x: du_parse(x, dayfirst=dayfirst, default=default)

else:
parse_date = date_parser

if time_parser is None:
parse_time = lambda x: du_parse(x)

else:
parse_time = time_parser

for i in range(n):
d = parse_date(str(dates[i]))
t = parse_time(str(times[i]))
result[i] = datetime(d.year, d.month, d.day,
t.hour, t.minute, t.second)

return result.base # .base to access underlying ndarray


def try_parse_year_month_day(
object[:] years, object[:] months, object[:] days
) -> np.ndarray:
Expand Down
129 changes: 0 additions & 129 deletions pandas/io/date_converters.py

This file was deleted.

21 changes: 8 additions & 13 deletions pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
from pandas.core.series import Series
from pandas.core.tools import datetimes as tools

from pandas.io.date_converters import generic_parser

if TYPE_CHECKING:
from pandas import DataFrame

Expand Down Expand Up @@ -1135,17 +1133,14 @@ def converter(*date_cols):
raise Exception("scalar parser")
return result
except Exception:
try:
return tools.to_datetime(
parsing.try_parse_dates(
parsing.concat_date_cols(date_cols),
parser=date_parser,
dayfirst=dayfirst,
),
errors="ignore",
)
except Exception:
return generic_parser(date_parser, *date_cols)
return tools.to_datetime(
parsing.try_parse_dates(
parsing.concat_date_cols(date_cols),
parser=date_parser,
dayfirst=dayfirst,
),
errors="ignore",
)

return converter

Expand Down
Loading

0 comments on commit 28405d8

Please sign in to comment.