From 44fd8b73fdaa28f07896d6846b7b04199315c7d1 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 19 Dec 2023 20:47:54 +0000 Subject: [PATCH] Fix code style issues with Black --- rocketpy/mathutils/function.py | 17 +++++---- rocketpy/tools.py | 70 ++++++++++++++++------------------ 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/rocketpy/mathutils/function.py b/rocketpy/mathutils/function.py index 9cfa32641..84936c84b 100644 --- a/rocketpy/mathutils/function.py +++ b/rocketpy/mathutils/function.py @@ -200,7 +200,7 @@ def set_source(self, source): self.__outputs__, self.__interpolation__, self.__extrapolation__, - ) + ) # If the source is a Function if isinstance(source, Function): source = source.get_source() @@ -211,7 +211,9 @@ def set_source(self, source): source = np.loadtxt(file, delimiter=",") except ValueError: # If an error occurs, headers are present - source = np.loadtxt(data_preprocessing(source), delimiter=",", dtype=np.float64) + source = np.loadtxt( + data_preprocessing(source), delimiter=",", dtype=np.float64 + ) except Exception as e: raise ValueError( "The source file is not a valid csv or txt file." @@ -1119,8 +1121,7 @@ def low_pass_filter(self, alpha): source=filtered_signal, interpolation=self.__interpolation__, extrapolation=self.__extrapolation__, - ) - + ) # Define all presentation methods def __call__(self, *args): @@ -2918,7 +2919,9 @@ def _check_user_input( source = np.loadtxt(source, delimiter=",", dtype=np.float64) except ValueError: # If an error occurs, there is a header - source = np.loadtxt(data_preprocessing(source), delimiter=",", dtype=np.float64) + source = np.loadtxt( + data_preprocessing(source), delimiter=",", dtype=np.float64 + ) except Exception as e: raise ValueError( "The source file is not a valid csv or txt file." @@ -2991,8 +2994,8 @@ def _check_user_input( + f"and output dimension ({in_out_dim})." ) return inputs, outputs, interpolation, extrapolation - - + + class PiecewiseFunction(Function): """Class for creating piecewise functions. These kind of functions are defined by a dictionary of functions, where the keys are tuples that diff --git a/rocketpy/tools.py b/rocketpy/tools.py index 07d2fa5e4..136a82a57 100644 --- a/rocketpy/tools.py +++ b/rocketpy/tools.py @@ -382,31 +382,31 @@ def check_requirement_version(module_name, version): return True - def is_float(element): - """ - Returns a boolean indicating us if an element is convertible to a float or not. - True : the element is convertible to a float - False : the element is not convertible to a float - - Parameters - ---------- - element : any - This is the element to test. - - Returns - ------- - result : boolean - The element is convertible or not. - """ - if element is None: - return False - try: - float(element) - return True - except ValueError: - return False - + """ + Returns a boolean indicating us if an element is convertible to a float or not. + True : the element is convertible to a float + False : the element is not convertible to a float + + Parameters + ---------- + element : any + This is the element to test. + + Returns + ------- + result : boolean + The element is convertible or not. + """ + if element is None: + return False + try: + float(element) + return True + except ValueError: + return False + + def return_first_data(source): """ Returns the first data of a CSV file. @@ -422,10 +422,10 @@ def return_first_data(source): The first data of the CSV file. """ native_data = open(source) - for row in native_data : - for value in row : + for row in native_data: + for value in row: return value - + def if_header(source): """ @@ -459,9 +459,9 @@ def data_preprocessing(source): Function The function with the incoming cleared CSV """ - output_path = 'cleaned_data.csv' - - with open(source, 'r') as file: + output_path = "cleaned_data.csv" + + with open(source, "r") as file: reader = csv.reader(file) header = next(reader) # Read the header @@ -476,12 +476,11 @@ def data_preprocessing(source): data_no_headers.append(row) # Save the processed data to a new CSV file - with open(output_path, 'w', encoding='utf-8') as output_file: - writer = csv.writer(output_file, delimiter=',') + with open(output_path, "w", encoding="utf-8") as output_file: + writer = csv.writer(output_file, delimiter=",") writer.writerows(data_no_headers) - + return output_path - if __name__ == "__main__": @@ -492,6 +491,3 @@ def data_preprocessing(source): print(f"All the {results.attempted} tests passed!") else: print(f"{results.failed} out of {results.attempted} tests failed.") - - -