Skip to main content

assert_unique

assert_unique()

Asserts that given subset of columns together have no duplicate rows. This assertion can be used with Layer dataset entities.

  • Parameters

    column_subset (List[str**]) -- Subset of the columns to be checked.

  • Returns

    Function object.

  • Return type

    Callable[[...], Any]

from layer.decorators.assertions import assert_unique
from layer.decorators import dataset

@dataset("user-data")
@assert_unique(["Id", "UserName", "Company"])
def create_my_dataset():
# Row 1 and Row 2 are duplicates. It throws an error.
data = [[1, "user1", "company1"], [1, "user1", "company1"], [1, "user1", "company2"]]
dataframe = pd.DataFrame(data, columns=["Id", "UserName", "Company"])
return dataframe