<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from . _smoothers_lowess import lowess as _lowess <EOL> def lowess ( endog , exog , frac = <NUM_LIT> / <NUM_LIT> , it = <NUM_LIT:3> , delta = <NUM_LIT:0.0> , is_sorted = False , <EOL> missing = '<STR_LIT>' , return_sorted = True ) : <EOL> '''<STR_LIT>''' <EOL> endog = np . asarray ( endog , float ) <EOL> exog = np . asarray ( exog , float ) <EOL> if exog . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if endog . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if endog . shape [ <NUM_LIT:0> ] != exog . shape [ <NUM_LIT:0> ] : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if missing in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> mask_valid = ( np . isfinite ( exog ) & np . isfinite ( endog ) ) <EOL> all_valid = np . all ( mask_valid ) <EOL> if all_valid : <EOL> y = endog <EOL> x = exog <EOL> else : <EOL> if missing == '<STR_LIT>' : <EOL> x = exog [ mask_valid ] <EOL> y = endog [ mask_valid ] <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> elif missing == '<STR_LIT:none>' : <EOL> y = endog <EOL> x = exog <EOL> all_valid = True <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not is_sorted : <EOL> sort_index = np . argsort ( x ) <EOL> x = np . array ( x [ sort_index ] ) <EOL> y = np . array ( y [ sort_index ] ) <EOL> res = _lowess ( y , x , frac = frac , it = it , delta = delta ) <EOL> _ , yfitted = res . T <EOL> if return_sorted : <EOL> return res <EOL> else : <EOL> if not is_sorted : <EOL> yfitted_ = np . empty_like ( y ) <EOL> yfitted_ . fill ( np . nan ) <EOL> yfitted_ [ sort_index ] = yfitted <EOL> yfitted = yfitted_ <EOL> else : <EOL> yfitted = yfitted <EOL> if not all_valid : <EOL> yfitted_ = np . empty_like ( endog ) <EOL> yfitted_ . fill ( np . nan ) <EOL> yfitted_ [ mask_valid ] = yfitted <EOL> yfitted = yfitted_ <EOL> return yfitted </s>
