Skip to content

Commit

Permalink
Make some archaic looking code more readable
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Mueller <[email protected]>
  • Loading branch information
johannes-mueller committed Sep 29, 2023
1 parent a7ef6fd commit 7498c32
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/pylife/materiallaws/woehlercurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,14 @@ def basquin_cycles(self, load, failure_probability=0.5):
cycles : numpy.ndarray
The cycle numbers at which the component fails for the given `load` values
"""
transformed = self.transform_to_failure_probability(failure_probability)
def ensure_float_to_prevent_int_overflow(load):
if isinstance(load, pd.Series):
return pd.Series(load, dtype=np.float64)
return np.asarray(load, dtype=np.float64)

if hasattr(load, '__iter__'):
if hasattr(load, 'astype'):
load = load.astype('float64')
else:
load = np.array(load).astype('float64')
else:
load = float(load)
transformed = self.transform_to_failure_probability(failure_probability)

load = ensure_float_to_prevent_int_overflow(load)
ld, wc = transformed.broadcast(load)
cycles = np.full_like(ld, np.inf)

Expand Down

0 comments on commit 7498c32

Please sign in to comment.