Skip to content

Commit d2e9723

Browse files
authored
DEP: Enforce deprecation of date converters for csv (#49086)
* DEP: Enforce deprecation of date converters for csv * Add whatsnew * Add check
1 parent 52acf97 commit d2e9723

File tree

7 files changed

+53
-311
lines changed

7 files changed

+53
-311
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ Deprecations
144144

145145
Removal of prior version deprecations/changes
146146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147+
- Removed Date parser functions :func:`~pandas.io.date_converters.parse_date_time`,
148+
:func:`~pandas.io.date_converters.parse_date_fields`, :func:`~pandas.io.date_converters.parse_all_fields`
149+
and :func:`~pandas.io.date_converters.generic_parser` (:issue:`24518`)
147150
- Remove argument ``squeeze`` from :meth:`DataFrame.groupby` and :meth:`Series.groupby` (:issue:`32380`)
148151
- Removed ``keep_tz`` argument in :meth:`DatetimeIndex.to_series` (:issue:`29731`)
149152
- Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`)

pandas/_libs/tslibs/parsing.pyi

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ def try_parse_dates(
2727
dayfirst: bool = ...,
2828
default: datetime | None = ...,
2929
) -> npt.NDArray[np.object_]: ...
30-
def try_parse_date_and_time(
31-
dates: npt.NDArray[np.object_], # object[:]
32-
times: npt.NDArray[np.object_], # object[:]
33-
date_parser=...,
34-
time_parser=...,
35-
dayfirst: bool = ...,
36-
default: datetime | None = ...,
37-
) -> npt.NDArray[np.object_]: ...
3830
def try_parse_year_month_day(
3931
years: npt.NDArray[np.object_], # object[:]
4032
months: npt.NDArray[np.object_], # object[:]

pandas/_libs/tslibs/parsing.pyx

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -741,49 +741,6 @@ def try_parse_dates(
741741
return result.base # .base to access underlying ndarray
742742

743743

744-
def try_parse_date_and_time(
745-
object[:] dates,
746-
object[:] times,
747-
date_parser=None,
748-
time_parser=None,
749-
bint dayfirst=False,
750-
default=None,
751-
) -> np.ndarray:
752-
cdef:
753-
Py_ssize_t i, n
754-
object[::1] result
755-
756-
n = len(dates)
757-
# TODO(cython3): Use len instead of `shape[0]`
758-
if times.shape[0] != n:
759-
raise ValueError('Length of dates and times must be equal')
760-
result = np.empty(n, dtype='O')
761-
762-
if date_parser is None:
763-
if default is None: # GH2618
764-
date = datetime.now()
765-
default = datetime(date.year, date.month, 1)
766-
767-
parse_date = lambda x: du_parse(x, dayfirst=dayfirst, default=default)
768-
769-
else:
770-
parse_date = date_parser
771-
772-
if time_parser is None:
773-
parse_time = lambda x: du_parse(x)
774-
775-
else:
776-
parse_time = time_parser
777-
778-
for i in range(n):
779-
d = parse_date(str(dates[i]))
780-
t = parse_time(str(times[i]))
781-
result[i] = datetime(d.year, d.month, d.day,
782-
t.hour, t.minute, t.second)
783-
784-
return result.base # .base to access underlying ndarray
785-
786-
787744
def try_parse_year_month_day(
788745
object[:] years, object[:] months, object[:] days
789746
) -> np.ndarray:

pandas/io/date_converters.py

Lines changed: 0 additions & 129 deletions
This file was deleted.

pandas/io/parsers/base_parser.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
from pandas.core.series import Series
7979
from pandas.core.tools import datetimes as tools
8080

81-
from pandas.io.date_converters import generic_parser
82-
8381
if TYPE_CHECKING:
8482
from pandas import DataFrame
8583

@@ -1135,17 +1133,14 @@ def converter(*date_cols):
11351133
raise Exception("scalar parser")
11361134
return result
11371135
except Exception:
1138-
try:
1139-
return tools.to_datetime(
1140-
parsing.try_parse_dates(
1141-
parsing.concat_date_cols(date_cols),
1142-
parser=date_parser,
1143-
dayfirst=dayfirst,
1144-
),
1145-
errors="ignore",
1146-
)
1147-
except Exception:
1148-
return generic_parser(date_parser, *date_cols)
1136+
return tools.to_datetime(
1137+
parsing.try_parse_dates(
1138+
parsing.concat_date_cols(date_cols),
1139+
parser=date_parser,
1140+
dayfirst=dayfirst,
1141+
),
1142+
errors="ignore",
1143+
)
11491144

11501145
return converter
11511146

0 commit comments

Comments
 (0)