Check if parse_dates are in columns. If user has provided names for parse_dates, check if those columns are available. Parameters ---------- columns : list List of names of the dataframe. Returns ------- The names of the columns which will get parsed l
(
parse_dates: bool | list, columns: Sequence[Hashable]
)
| 873 | |
| 874 | |
| 875 | def validate_parse_dates_presence( |
| 876 | parse_dates: bool | list, columns: Sequence[Hashable] |
| 877 | ) -> set: |
| 878 | """ |
| 879 | Check if parse_dates are in columns. |
| 880 | |
| 881 | If user has provided names for parse_dates, check if those columns |
| 882 | are available. |
| 883 | |
| 884 | Parameters |
| 885 | ---------- |
| 886 | columns : list |
| 887 | List of names of the dataframe. |
| 888 | |
| 889 | Returns |
| 890 | ------- |
| 891 | The names of the columns which will get parsed later if a list |
| 892 | is given as specification. |
| 893 | |
| 894 | Raises |
| 895 | ------ |
| 896 | ValueError |
| 897 | If column to parse_date is not in dataframe. |
| 898 | |
| 899 | """ |
| 900 | if not isinstance(parse_dates, list): |
| 901 | return set() |
| 902 | |
| 903 | missing = set() |
| 904 | unique_cols = set() |
| 905 | for col in parse_dates: |
| 906 | if isinstance(col, str): |
| 907 | if col not in columns: |
| 908 | missing.add(col) |
| 909 | else: |
| 910 | unique_cols.add(col) |
| 911 | elif col in columns: |
| 912 | unique_cols.add(col) |
| 913 | else: |
| 914 | unique_cols.add(columns[col]) |
| 915 | if missing: |
| 916 | missing_cols = ", ".join(sorted(missing)) |
| 917 | raise ValueError(f"Missing column provided to 'parse_dates': '{missing_cols}'") |
| 918 | return unique_cols |
| 919 | |
| 920 | |
| 921 | def _validate_usecols_arg(usecols): |
no test coverage detected