MCPcopy
hub / github.com/pandas-dev/pandas / _validate_usecols_names

Method _validate_usecols_names

pandas/io/parsers/base_parser.py:638–667  ·  view source on GitHub ↗

Validates that all usecols are present in a given list of names. If not, raise a ValueError that shows what usecols are missing. Parameters ---------- usecols : iterable of usecols The columns to validate are present in names. nam

(self, usecols: SequenceT, names: Sequence)

Source from the content-addressed store, hash-verified

636
637 @final
638 def _validate_usecols_names(self, usecols: SequenceT, names: Sequence) -> SequenceT:
639 """
640 Validates that all usecols are present in a given
641 list of names. If not, raise a ValueError that
642 shows what usecols are missing.
643
644 Parameters
645 ----------
646 usecols : iterable of usecols
647 The columns to validate are present in names.
648 names : iterable of names
649 The column names to check against.
650
651 Returns
652 -------
653 usecols : iterable of usecols
654 The `usecols` parameter if the validation succeeds.
655
656 Raises
657 ------
658 ValueError : Columns were missing. Error message will list them.
659 """
660 missing = [c for c in usecols if c not in names]
661 if len(missing) > 0:
662 raise ValueError(
663 f"Usecols do not match columns, columns expected but not found: "
664 f"{missing}"
665 )
666
667 return usecols
668
669 @final
670 def _clean_index_names(self, columns, index_col) -> tuple[list | None, list, list]:

Callers 2

__init__Method · 0.80
_handle_usecolsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected