Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Dec 19, 2023
1 parent 36fb82b commit 44fd8b7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
17 changes: 10 additions & 7 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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."
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down
70 changes: 33 additions & 37 deletions rocketpy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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

Expand All @@ -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__":
Expand All @@ -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.")



0 comments on commit 44fd8b7

Please sign in to comment.