Skip to content

Commit 695fa6f

Browse files
committed
deprecated convert_dates and keep_default_dates
1 parent aa4dc71 commit 695fa6f

File tree

5 files changed

+7
-97
lines changed

5 files changed

+7
-97
lines changed

doc/source/user_guide/io.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,6 @@ is ``None``. To explicitly force ``Series`` parsing, pass ``typ=series``
19261926
* ``dtype`` : if True, infer dtypes, if a dict of column to dtype, then use those, if ``False``, then don't infer dtypes at all, default is True, apply only to the data.
19271927
* ``convert_axes`` : boolean, try to convert the axes to the proper dtypes, default is ``True``
19281928
* ``convert_dates`` : a list of columns to parse for dates; If ``True``, then try to parse date-like columns, default is ``True``.
1929-
* ``keep_default_dates`` : boolean, default ``True``. If parsing dates, then parse the default date-like columns.
19301929
* ``precise_float`` : boolean, default ``False``. Set to enable usage of higher precision (strtod) function when decoding string to double values. Default (``False``) is to use fast but less precise builtin functionality.
19311930
* ``date_unit`` : string, the timestamp unit to detect if converting dates. Default
19321931
None. By default the timestamp precision will be detected, if this is not desired

pandas/io/json/_json.py

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ def read_json(
406406
typ: Literal["frame"] = ...,
407407
dtype: DtypeArg | None = ...,
408408
convert_axes: bool | None = ...,
409-
convert_dates: bool | list[str] = ...,
410-
keep_default_dates: bool = ...,
411409
precise_float: bool = ...,
412410
date_unit: str | None = ...,
413411
encoding: str | None = ...,
@@ -430,8 +428,6 @@ def read_json(
430428
typ: Literal["series"],
431429
dtype: DtypeArg | None = ...,
432430
convert_axes: bool | None = ...,
433-
convert_dates: bool | list[str] = ...,
434-
keep_default_dates: bool = ...,
435431
precise_float: bool = ...,
436432
date_unit: str | None = ...,
437433
encoding: str | None = ...,
@@ -454,8 +450,6 @@ def read_json(
454450
typ: Literal["series"],
455451
dtype: DtypeArg | None = ...,
456452
convert_axes: bool | None = ...,
457-
convert_dates: bool | list[str] = ...,
458-
keep_default_dates: bool = ...,
459453
precise_float: bool = ...,
460454
date_unit: str | None = ...,
461455
encoding: str | None = ...,
@@ -478,8 +472,6 @@ def read_json(
478472
typ: Literal["frame"] = ...,
479473
dtype: DtypeArg | None = ...,
480474
convert_axes: bool | None = ...,
481-
convert_dates: bool | list[str] = ...,
482-
keep_default_dates: bool = ...,
483475
precise_float: bool = ...,
484476
date_unit: str | None = ...,
485477
encoding: str | None = ...,
@@ -505,8 +497,6 @@ def read_json(
505497
typ: Literal["frame", "series"] = "frame",
506498
dtype: DtypeArg | None = None,
507499
convert_axes: bool | None = None,
508-
convert_dates: bool | list[str] = True,
509-
keep_default_dates: bool = True,
510500
precise_float: bool = False,
511501
date_unit: str | None = None,
512502
encoding: str | None = None,
@@ -588,29 +578,6 @@ def read_json(
588578
589579
For all ``orient`` values except ``'table'``, default is True.
590580
591-
convert_dates : bool or list of str, default True
592-
If True then default datelike columns may be converted (depending on
593-
keep_default_dates).
594-
If False, no dates will be converted.
595-
If a list of column names, then those columns will be converted and
596-
default datelike columns may also be converted (depending on
597-
keep_default_dates).
598-
599-
keep_default_dates : bool, default True
600-
If parsing dates (convert_dates is not False), then try to parse the
601-
default datelike columns.
602-
A column label is datelike if
603-
604-
* it ends with ``'_at'``,
605-
606-
* it ends with ``'_time'``,
607-
608-
* it begins with ``'timestamp'``,
609-
610-
* it is ``'modified'``, or
611-
612-
* it is ``'date'``.
613-
614581
precise_float : bool, default False
615582
Set to enable usage of higher precision (strtod) function when
616583
decoding string to double values. Default (False) is to use fast but
@@ -786,8 +753,6 @@ def read_json(
786753
typ=typ,
787754
dtype=dtype,
788755
convert_axes=convert_axes,
789-
convert_dates=convert_dates,
790-
keep_default_dates=keep_default_dates,
791756
precise_float=precise_float,
792757
date_unit=date_unit,
793758
encoding=encoding,
@@ -823,8 +788,6 @@ def __init__(
823788
typ: FrameSeriesStrT,
824789
dtype,
825790
convert_axes: bool | None,
826-
convert_dates,
827-
keep_default_dates: bool,
828791
precise_float: bool,
829792
date_unit,
830793
encoding,
@@ -841,8 +804,6 @@ def __init__(
841804
self.typ = typ
842805
self.dtype = dtype
843806
self.convert_axes = convert_axes
844-
self.convert_dates = convert_dates
845-
self.keep_default_dates = keep_default_dates
846807
self.precise_float = precise_float
847808
self.date_unit = date_unit
848809
self.encoding = encoding
@@ -982,8 +943,6 @@ def _get_object_parser(self, json: str) -> DataFrame | Series:
982943
"orient": self.orient,
983944
"dtype": self.dtype,
984945
"convert_axes": self.convert_axes,
985-
"convert_dates": self.convert_dates,
986-
"keep_default_dates": self.keep_default_dates,
987946
"precise_float": self.precise_float,
988947
"date_unit": self.date_unit,
989948
"dtype_backend": self.dtype_backend,
@@ -1080,8 +1039,6 @@ def __init__(
10801039
orient,
10811040
dtype: DtypeArg | None = None,
10821041
convert_axes: bool = True,
1083-
convert_dates: bool | list[str] = True,
1084-
keep_default_dates: bool = False,
10851042
precise_float: bool = False,
10861043
date_unit=None,
10871044
dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
@@ -1105,9 +1062,7 @@ def __init__(
11051062

11061063
self.precise_float = precise_float
11071064
self.convert_axes = convert_axes
1108-
self.convert_dates = convert_dates
11091065
self.date_unit = date_unit
1110-
self.keep_default_dates = keep_default_dates
11111066
self.dtype_backend = dtype_backend
11121067

11131068
@final
@@ -1144,7 +1099,6 @@ def _convert_axes(self, obj: DataFrame | Series) -> DataFrame | Series:
11441099
name=axis_name,
11451100
data=ser,
11461101
use_dtypes=False,
1147-
convert_dates=True,
11481102
is_axis=True,
11491103
)
11501104
if result:
@@ -1161,7 +1115,6 @@ def _try_convert_data(
11611115
name: Hashable,
11621116
data: Series,
11631117
use_dtypes: bool = True,
1164-
convert_dates: bool | list[str] = True,
11651118
is_axis: bool = False,
11661119
) -> tuple[Series, bool]:
11671120
"""
@@ -1179,10 +1132,7 @@ def _try_convert_data(
11791132

11801133
elif self.dtype is True:
11811134
pass
1182-
elif not _should_convert_dates(
1183-
convert_dates, self.keep_default_dates, name
1184-
):
1185-
# convert_dates takes precedence over columns listed in dtypes
1135+
else:
11861136
dtype = (
11871137
self.dtype.get(name) if isinstance(self.dtype, dict) else self.dtype
11881138
)
@@ -1192,11 +1142,6 @@ def _try_convert_data(
11921142
except (TypeError, ValueError):
11931143
return data, False
11941144

1195-
if convert_dates:
1196-
new_data = self._try_convert_to_date(data)
1197-
if new_data is not data:
1198-
return new_data, True
1199-
12001145
converted = False
12011146
if self.dtype_backend is not lib.no_default and not is_axis:
12021147
# Fall through for conversion later on
@@ -1302,7 +1247,7 @@ def _parse(self) -> Series:
13021247
return Series(data)
13031248

13041249
def _try_convert_types(self, obj: Series) -> Series:
1305-
obj, _ = self._try_convert_data("data", obj, convert_dates=self.convert_dates)
1250+
obj, _ = self._try_convert_data("data", obj)
13061251
return obj
13071252

13081253

@@ -1349,40 +1294,8 @@ def _try_convert_types(self, obj: DataFrame) -> DataFrame:
13491294
result, _ = self._try_convert_data(
13501295
col_label,
13511296
series,
1352-
convert_dates=_should_convert_dates(
1353-
self.convert_dates,
1354-
keep_default_dates=self.keep_default_dates,
1355-
col=col_label,
1356-
),
13571297
)
13581298
arrays.append(result.array)
13591299
return DataFrame._from_arrays(
13601300
arrays, obj.columns, obj.index, verify_integrity=False
13611301
)
1362-
1363-
1364-
def _should_convert_dates(
1365-
convert_dates: bool | list[str],
1366-
keep_default_dates: bool,
1367-
col: Hashable,
1368-
) -> bool:
1369-
"""
1370-
Return bool whether a DataFrame column should be cast to datetime.
1371-
"""
1372-
if convert_dates is False:
1373-
# convert_dates=True means follow keep_default_dates
1374-
return False
1375-
elif not isinstance(convert_dates, bool) and col in set(convert_dates):
1376-
return True
1377-
elif not keep_default_dates:
1378-
return False
1379-
elif not isinstance(col, str):
1380-
return False
1381-
col_lower = col.lower()
1382-
if (
1383-
col_lower.endswith(("_at", "_time"))
1384-
or col_lower in {"modified", "date", "datetime"}
1385-
or col_lower.startswith("timestamp")
1386-
):
1387-
return True
1388-
return False

pandas/tests/io/json/test_pandas.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test_frame_non_unique_columns(self, orient, data, request):
152152

153153
with tm.assert_produces_warning(expected_warning, match=msg):
154154
result = read_json(
155-
StringIO(df.to_json(orient=orient)), orient=orient, convert_dates=["x"]
155+
StringIO(df.to_json(orient=orient)), orient=orient
156156
)
157157
if orient == "values":
158158
expected = DataFrame(data)
@@ -840,7 +840,7 @@ def test_convert_dates(self, datetime_series, datetime_frame):
840840
with tm.assert_produces_warning(FutureWarning, match=msg):
841841
json = StringIO(df.to_json(date_unit="ns"))
842842

843-
result = read_json(json, convert_dates=False)
843+
result = read_json(json)
844844
expected = df.copy()
845845
expected["date"] = expected["date"].values.view("i8")
846846
expected["foo"] = expected["foo"].astype("int64")
@@ -1056,7 +1056,7 @@ def test_iso_non_nano_datetimes(self, unit):
10561056
# TODO: check_dtype/check_index_type should be removable
10571057
# once read_json gets non-nano support
10581058
tm.assert_frame_equal(
1059-
read_json(buf, convert_dates=["date", "date_obj"]),
1059+
read_json(buf),
10601060
df,
10611061
check_index_type=False,
10621062
check_dtype=False,
@@ -1125,7 +1125,7 @@ def test_round_trip_exception(self, datapath):
11251125
def test_url(self, field, dtype, httpserver):
11261126
data = '{"created_at": ["2023-06-23T18:21:36Z"], "closed_at": ["2023-06-23T18:21:36"], "updated_at": ["2023-06-23T18:21:36Z"]}\n' # noqa: E501
11271127
httpserver.serve_content(content=data)
1128-
result = read_json(httpserver.url, convert_dates=True)
1128+
result = read_json(httpserver.url)
11291129
assert result[field].dtype == dtype
11301130

11311131
def test_timedelta(self):

pandas/tests/io/json/test_readlines.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ def test_readjson_chunks_closes(chunksize):
224224
typ="frame",
225225
dtype=True,
226226
convert_axes=True,
227-
convert_dates=True,
228-
keep_default_dates=True,
229227
precise_float=False,
230228
date_unit=None,
231229
encoding=None,

pandas/tests/io/test_gcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_to_read_gcs(gcs_buffer, format, monkeypatch, capsys, request):
8686
)
8787
with tm.assert_produces_warning(FutureWarning, match=msg):
8888
df1.to_json(path)
89-
df2 = read_json(path, convert_dates=["dt"])
89+
df2 = read_json(path)
9090
elif format == "parquet":
9191
pytest.importorskip("pyarrow")
9292
pa_fs = pytest.importorskip("pyarrow.fs")

0 commit comments

Comments
 (0)