Skip to content

Commit

Permalink
Simplfied validation decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik-Geo committed Jul 8, 2024
1 parent 954c3ed commit 24f5c6a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 35 deletions.
4 changes: 2 additions & 2 deletions geost/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def is_inclined(self):
return self.__is_inclined

@header.setter
@validate_header()
@validate_header
def header(self, header):
"""
This setter is called whenever the attribute 'header' is manipulated, either
Expand All @@ -238,7 +238,7 @@ def header(self, header):
self.__check_header_to_data_alignment()

@data.setter
@validate_data()
@validate_data
def data(self, data):
"""
This setter is called whenever the attribute 'data' is manipulated, either
Expand Down
60 changes: 27 additions & 33 deletions geost/validate/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,38 @@
validationschemas = ValidationSchemas()


def validate_header():
def decorator(f):
@wraps(f)
def wrapper(*args):
dataframe_to_validate = args[1]
validation_instance = DataFrameSchema(
"Header validation", validationschemas.headerschema
)
validation_instance.validate(dataframe_to_validate)
return f(*args)
def validate_header(f):
@wraps(f)
def wrapper(*args):
dataframe_to_validate = args[1]
validation_instance = DataFrameSchema(
"Header validation", validationschemas.headerschema
)
validation_instance.validate(dataframe_to_validate)
return f(*args)

return wrapper
return wrapper

return decorator

def validate_data(f):
@wraps(f)
def wrapper(*args):
collection_object = args[0]
dataframe_to_validate = args[1]

def validate_data():
def decorator(f):
@wraps(f)
def wrapper(*args):
collection_object = args[0]
dataframe_to_validate = args[1]
# Determine what the validation conditions are and append to 'schema_to_use'
if collection_object.vertical_reference == "depth":
schema_to_use = validationschemas.common_dataschema_depth_reference
else:
schema_to_use = validationschemas.common_dataschema

# Determine what the validation conditions are and append to 'schema_to_use'
if collection_object.vertical_reference == "depth":
schema_to_use = validationschemas.common_dataschema_depth_reference
else:
schema_to_use = validationschemas.common_dataschema
if collection_object.is_inclined:
schema_to_use = schema_to_use | validationschemas.inclined_dataschema

if collection_object.is_inclined:
schema_to_use = schema_to_use | validationschemas.inclined_dataschema
# Use the acquired validation conditions for validation
validation_instance = DataFrameSchema("Data validation", schema_to_use)
validation_instance.validate(dataframe_to_validate)

# Use the acquired validation conditions for validation
validation_instance = DataFrameSchema("Data validation", schema_to_use)
validation_instance.validate(dataframe_to_validate)
return f(*args)

return f(*args)

return wrapper

return decorator
return wrapper

0 comments on commit 24f5c6a

Please sign in to comment.