|
41 | 41 | from pandas.core.dtypes.common import (
|
42 | 42 | is_file_like,
|
43 | 43 | is_float,
|
| 44 | + is_hashable, |
44 | 45 | is_integer,
|
45 | 46 | is_list_like,
|
46 | 47 | pandas_dtype,
|
@@ -649,7 +650,7 @@ def read_csv(
|
649 | 650 | skip_blank_lines: bool = ...,
|
650 | 651 | parse_dates: bool | Sequence[Hashable] | None = ...,
|
651 | 652 | infer_datetime_format: bool | lib.NoDefault = ...,
|
652 |
| - keep_date_col: bool = ..., |
| 653 | + keep_date_col: bool | lib.NoDefault = ..., |
653 | 654 | date_parser: Callable | lib.NoDefault = ...,
|
654 | 655 | date_format: str | dict[Hashable, str] | None = ...,
|
655 | 656 | dayfirst: bool = ...,
|
@@ -709,7 +710,7 @@ def read_csv(
|
709 | 710 | skip_blank_lines: bool = ...,
|
710 | 711 | parse_dates: bool | Sequence[Hashable] | None = ...,
|
711 | 712 | infer_datetime_format: bool | lib.NoDefault = ...,
|
712 |
| - keep_date_col: bool = ..., |
| 713 | + keep_date_col: bool | lib.NoDefault = ..., |
713 | 714 | date_parser: Callable | lib.NoDefault = ...,
|
714 | 715 | date_format: str | dict[Hashable, str] | None = ...,
|
715 | 716 | dayfirst: bool = ...,
|
@@ -769,7 +770,7 @@ def read_csv(
|
769 | 770 | skip_blank_lines: bool = ...,
|
770 | 771 | parse_dates: bool | Sequence[Hashable] | None = ...,
|
771 | 772 | infer_datetime_format: bool | lib.NoDefault = ...,
|
772 |
| - keep_date_col: bool = ..., |
| 773 | + keep_date_col: bool | lib.NoDefault = ..., |
773 | 774 | date_parser: Callable | lib.NoDefault = ...,
|
774 | 775 | date_format: str | dict[Hashable, str] | None = ...,
|
775 | 776 | dayfirst: bool = ...,
|
@@ -829,7 +830,7 @@ def read_csv(
|
829 | 830 | skip_blank_lines: bool = ...,
|
830 | 831 | parse_dates: bool | Sequence[Hashable] | None = ...,
|
831 | 832 | infer_datetime_format: bool | lib.NoDefault = ...,
|
832 |
| - keep_date_col: bool = ..., |
| 833 | + keep_date_col: bool | lib.NoDefault = ..., |
833 | 834 | date_parser: Callable | lib.NoDefault = ...,
|
834 | 835 | date_format: str | dict[Hashable, str] | None = ...,
|
835 | 836 | dayfirst: bool = ...,
|
@@ -903,7 +904,7 @@ def read_csv(
|
903 | 904 | # Datetime Handling
|
904 | 905 | parse_dates: bool | Sequence[Hashable] | None = None,
|
905 | 906 | infer_datetime_format: bool | lib.NoDefault = lib.no_default,
|
906 |
| - keep_date_col: bool = False, |
| 907 | + keep_date_col: bool | lib.NoDefault = lib.no_default, |
907 | 908 | date_parser: Callable | lib.NoDefault = lib.no_default,
|
908 | 909 | date_format: str | dict[Hashable, str] | None = None,
|
909 | 910 | dayfirst: bool = False,
|
@@ -934,6 +935,38 @@ def read_csv(
|
934 | 935 | storage_options: StorageOptions | None = None,
|
935 | 936 | dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
|
936 | 937 | ) -> DataFrame | TextFileReader:
|
| 938 | + if keep_date_col is not lib.no_default: |
| 939 | + # GH#55569 |
| 940 | + warnings.warn( |
| 941 | + "The 'keep_date_col' keyword in pd.read_csv is deprecated and " |
| 942 | + "will be removed in a future version. Explicitly remove unwanted " |
| 943 | + "columns after parsing instead.", |
| 944 | + FutureWarning, |
| 945 | + stacklevel=find_stack_level(), |
| 946 | + ) |
| 947 | + else: |
| 948 | + keep_date_col = False |
| 949 | + |
| 950 | + if lib.is_list_like(parse_dates): |
| 951 | + # GH#55569 |
| 952 | + depr = False |
| 953 | + # error: Item "bool" of "bool | Sequence[Hashable] | None" has no |
| 954 | + # attribute "__iter__" (not iterable) |
| 955 | + if not all(is_hashable(x) for x in parse_dates): # type: ignore[union-attr] |
| 956 | + depr = True |
| 957 | + elif isinstance(parse_dates, dict) and any( |
| 958 | + lib.is_list_like(x) for x in parse_dates.values() |
| 959 | + ): |
| 960 | + depr = True |
| 961 | + if depr: |
| 962 | + warnings.warn( |
| 963 | + "Support for nested sequences for 'parse_dates' in pd.read_csv " |
| 964 | + "is deprecated. Combine the desired columns with pd.to_datetime " |
| 965 | + "after parsing instead.", |
| 966 | + FutureWarning, |
| 967 | + stacklevel=find_stack_level(), |
| 968 | + ) |
| 969 | + |
937 | 970 | if infer_datetime_format is not lib.no_default:
|
938 | 971 | warnings.warn(
|
939 | 972 | "The argument 'infer_datetime_format' is deprecated and will "
|
@@ -1004,7 +1037,7 @@ def read_table(
|
1004 | 1037 | skip_blank_lines: bool = ...,
|
1005 | 1038 | parse_dates: bool | Sequence[Hashable] = ...,
|
1006 | 1039 | infer_datetime_format: bool | lib.NoDefault = ...,
|
1007 |
| - keep_date_col: bool = ..., |
| 1040 | + keep_date_col: bool | lib.NoDefault = ..., |
1008 | 1041 | date_parser: Callable | lib.NoDefault = ...,
|
1009 | 1042 | date_format: str | dict[Hashable, str] | None = ...,
|
1010 | 1043 | dayfirst: bool = ...,
|
@@ -1061,7 +1094,7 @@ def read_table(
|
1061 | 1094 | skip_blank_lines: bool = ...,
|
1062 | 1095 | parse_dates: bool | Sequence[Hashable] = ...,
|
1063 | 1096 | infer_datetime_format: bool | lib.NoDefault = ...,
|
1064 |
| - keep_date_col: bool = ..., |
| 1097 | + keep_date_col: bool | lib.NoDefault = ..., |
1065 | 1098 | date_parser: Callable | lib.NoDefault = ...,
|
1066 | 1099 | date_format: str | dict[Hashable, str] | None = ...,
|
1067 | 1100 | dayfirst: bool = ...,
|
@@ -1118,7 +1151,7 @@ def read_table(
|
1118 | 1151 | skip_blank_lines: bool = ...,
|
1119 | 1152 | parse_dates: bool | Sequence[Hashable] = ...,
|
1120 | 1153 | infer_datetime_format: bool | lib.NoDefault = ...,
|
1121 |
| - keep_date_col: bool = ..., |
| 1154 | + keep_date_col: bool | lib.NoDefault = ..., |
1122 | 1155 | date_parser: Callable | lib.NoDefault = ...,
|
1123 | 1156 | date_format: str | dict[Hashable, str] | None = ...,
|
1124 | 1157 | dayfirst: bool = ...,
|
@@ -1175,7 +1208,7 @@ def read_table(
|
1175 | 1208 | skip_blank_lines: bool = ...,
|
1176 | 1209 | parse_dates: bool | Sequence[Hashable] = ...,
|
1177 | 1210 | infer_datetime_format: bool | lib.NoDefault = ...,
|
1178 |
| - keep_date_col: bool = ..., |
| 1211 | + keep_date_col: bool | lib.NoDefault = ..., |
1179 | 1212 | date_parser: Callable | lib.NoDefault = ...,
|
1180 | 1213 | date_format: str | dict[Hashable, str] | None = ...,
|
1181 | 1214 | dayfirst: bool = ...,
|
@@ -1248,7 +1281,7 @@ def read_table(
|
1248 | 1281 | # Datetime Handling
|
1249 | 1282 | parse_dates: bool | Sequence[Hashable] = False,
|
1250 | 1283 | infer_datetime_format: bool | lib.NoDefault = lib.no_default,
|
1251 |
| - keep_date_col: bool = False, |
| 1284 | + keep_date_col: bool | lib.NoDefault = lib.no_default, |
1252 | 1285 | date_parser: Callable | lib.NoDefault = lib.no_default,
|
1253 | 1286 | date_format: str | dict[Hashable, str] | None = None,
|
1254 | 1287 | dayfirst: bool = False,
|
@@ -1279,6 +1312,29 @@ def read_table(
|
1279 | 1312 | storage_options: StorageOptions | None = None,
|
1280 | 1313 | dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
|
1281 | 1314 | ) -> DataFrame | TextFileReader:
|
| 1315 | + if keep_date_col is not lib.no_default: |
| 1316 | + # GH#55569 |
| 1317 | + warnings.warn( |
| 1318 | + "The 'keep_date_col' keyword in pd.read_table is deprecated and " |
| 1319 | + "will be removed in a future version. Explicitly remove unwanted " |
| 1320 | + "columns after parsing instead.", |
| 1321 | + FutureWarning, |
| 1322 | + stacklevel=find_stack_level(), |
| 1323 | + ) |
| 1324 | + else: |
| 1325 | + keep_date_col = False |
| 1326 | + |
| 1327 | + # error: Item "bool" of "bool | Sequence[Hashable]" has no attribute "__iter__" |
| 1328 | + if lib.is_list_like(parse_dates) and not all(is_hashable(x) for x in parse_dates): # type: ignore[union-attr] |
| 1329 | + # GH#55569 |
| 1330 | + warnings.warn( |
| 1331 | + "Support for nested sequences for 'parse_dates' in pd.read_table " |
| 1332 | + "is deprecated. Combine the desired columns with pd.to_datetime " |
| 1333 | + "after parsing instead.", |
| 1334 | + FutureWarning, |
| 1335 | + stacklevel=find_stack_level(), |
| 1336 | + ) |
| 1337 | + |
1282 | 1338 | if infer_datetime_format is not lib.no_default:
|
1283 | 1339 | warnings.warn(
|
1284 | 1340 | "The argument 'infer_datetime_format' is deprecated and will "
|
|
0 commit comments