prokbert.general_utils.is_valid_primary_key

prokbert.general_utils.is_valid_primary_key(df: DataFrame, column_name: str) bool

Checks if a specified column in a DataFrame can serve as a valid primary key.

Parameters
  • df (pd.DataFrame) – The input DataFrame to be checked.

  • column_name (str) – The name of the column to check.

Returns

True if the column can serve as a valid primary key, False otherwise.

Return type

bool

Raises

ValueError – If the specified column does not exist in the DataFrame.

>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
>>> is_valid_primary_key(df, 'A')
True
>>> df = pd.DataFrame({'A': [1, 2, 2], 'B': [4, 5, 6]})
>>> is_valid_primary_key(df, 'A')
False