multimeric / PandasSchema

A validation library for Pandas data frames using user-friendly schemas
https://multimeric.github.io/PandasSchema/
GNU General Public License v3.0
189 stars 35 forks source link

Concatenate several schemas into a single one #36

Open deponovo opened 4 years ago

deponovo commented 4 years ago

Hi, it would be nice to have a __or__ method in the Schema class to concatenate schemas. I cannot create a branch for this in the mean time, but if somebody could, here is an implementation proposal.

class Schema:
    def __or__(self, other):
        if not isinstance(other, Schema):
            raise TypeError(f'{self.__class__.__name__} can only be concatenated with another `Schema`, found {type(other)}.'

        concat_columns = self.columns.extend(other.columns)
        concat_schemas = Schema(columns=concat_columns)
        return concat_schemas 
multimeric commented 4 years ago

I'll consider an implementation of this in the next major version.