From b6e24b63f3e3d173f65ddebc5db4e86d40f2eb77 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 21:52:18 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- movement/validators/files.py | 54 ++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/movement/validators/files.py b/movement/validators/files.py index fbc4afee..dfc6df3b 100644 --- a/movement/validators/files.py +++ b/movement/validators/files.py @@ -219,7 +219,8 @@ def _file_contains_expected_levels(self, attribute, value): ".csv header rows do not match the known format for " "DeepLabCut pose estimation output files.", ) - + + @define class ValidAniposeCSV: """Class for validating Anipose-style .csv files. @@ -248,43 +249,66 @@ def _file_contains_expected_headers(self, attribute, value): These are to be found among the top 4 rows of the file. """ - expected_header_suffixes = ["_x", "_y", "_z", "_score", "_error", "_ncams"] - expected_headers = ["fnum", "center_0", "center_1", "center_2", - "M_00", "M_01", "M_02", "M_10", "M_11", - "M_12", "M_20", "M_21", "M_22"] - + expected_header_suffixes = [ + "_x", + "_y", + "_z", + "_score", + "_error", + "_ncams", + ] + expected_headers = [ + "fnum", + "center_0", + "center_1", + "center_2", + "M_00", + "M_01", + "M_02", + "M_10", + "M_11", + "M_12", + "M_20", + "M_21", + "M_22", + ] + # Read the first line of the CSV to get the headers with open(value) as f: headers = f.readline().strip().split(",") - + # Check that all expected headers are present if not all(h in headers for h in expected_headers): raise log_error( ValueError, "CSV file is missing some expected headers." - f"Expected: {expected_headers}." + f"Expected: {expected_headers}.", ) - + # For all other headers, check they have expected suffixes and base names other_headers = [h for h in headers if h not in expected_headers] for header in other_headers: # Check suffix - if not any(header.endswith(suffix) for suffix in expected_header_suffixes): + if not any( + header.endswith(suffix) for suffix in expected_header_suffixes + ): raise log_error( ValueError, - f"Header {header} does not have an expected suffix." + f"Header {header} does not have an expected suffix.", ) # Get base name by removing suffix base = header.rsplit("_", 1)[0] # Check base name has all expected suffixes - if not all(f"{base}{suffix}" in headers for suffix in expected_header_suffixes): + if not all( + f"{base}{suffix}" in headers + for suffix in expected_header_suffixes + ): raise log_error( - ValueError, + ValueError, f"Base header {base} is missing some expected suffixes." f"Expected: {expected_header_suffixes};" - f"Got: {headers}." + f"Got: {headers}.", ) - @define