Minor modification in handling strings (#1301)

* Style modifications to fbprophet

* fixing cases where tests were broken

* minor style changes

* changed f-strings to named formatted strings due to Python2 build

* fixing syntax errors

* switching to formatted string quoting using {!r}

* Fixing ValueError Styling in my own branch

* fixing type and changing back one quoted string
This commit is contained in:
Benjamin Ogorek 2020-01-28 18:24:40 -05:00 committed by GitHub
parent 1f6170491d
commit 0a270b4a19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -198,27 +198,27 @@ class Prophet(object):
'ds', 'y', 'cap', 'floor', 'y_scaled', 'cap_scaled'])
if name in reserved_names:
raise ValueError(
'Name "{name}" is reserved.'.format(name=name)
'Name {name!r} is reserved.'.format(name=name)
)
if (check_holidays and self.holidays is not None and
name in self.holidays['holiday'].unique()):
raise ValueError(
'Name "{name}" already used for a holiday.'.format(name=name)
'Name {name!r} already used for a holiday.'.format(name=name)
)
if (check_holidays and self.country_holidays is not None and
name in get_holiday_names(self.country_holidays)):
raise ValueError(
'Name "{name}" is a holiday name in {country_holidays}.'
'Name {name!r} is a holiday name in {country_holidays}.'
.format(name=name, country_holidays=self.country_holidays)
)
if check_seasonalities and name in self.seasonalities:
raise ValueError(
'Name "{name}" already used for a seasonality.'
'Name {name!r} already used for a seasonality.'
.format(name=name)
)
if check_regressors and name in self.extra_regressors:
raise ValueError(
'Name "{name}" already used for an added regressor.'
'Name {name!r} already used for an added regressor.'
.format(name=name)
)
@ -256,24 +256,27 @@ class Prophet(object):
for name in self.extra_regressors:
if name not in df:
raise ValueError(
'Regressor "{name}" missing from dataframe'
.format(name=name))
'Regressor {name!r} missing from dataframe'
.format(name=name)
)
df[name] = pd.to_numeric(df[name])
if df[name].isnull().any():
raise ValueError(
'Found NaN in column {name}'.format(name=name)
'Found NaN in column {name!r}'.format(name=name)
)
for props in self.seasonalities.values():
condition_name = props['condition_name']
if condition_name is not None:
if condition_name not in df:
raise ValueError(
'Condition "{condition_name}" missing from dataframe'
.format(condition_name=condition_name))
'Condition {condition_name!r} missing from dataframe'
.format(condition_name=condition_name)
)
if not df[condition_name].isin([True, False]).all():
raise ValueError(
'Found non-boolean in column {condition_name}'
.format(condition_name=condition_name))
'Found non-boolean in column {condition_name!r}'
.format(condition_name=condition_name)
)
df[condition_name] = df[condition_name].astype('bool')
if df.index.name == 'ds':
@ -527,7 +530,7 @@ class Prophet(object):
ps = float(self.holidays_prior_scale)
if row.holiday in prior_scales and prior_scales[row.holiday] != ps:
raise ValueError(
'Holiday {holiday} does not have consistent prior '
'Holiday {holiday!r} does not have consistent prior '
'scale specification.'.format(holiday=row.holiday)
)
if ps <= 0:
@ -710,8 +713,8 @@ class Prophet(object):
# Set the holidays.
if self.country_holidays is not None:
logger.warning(
'Changing country holidays from {country_holidays} to '
'{country_name}.'
'Changing country holidays from {country_holidays!r} to '
'{country_name!r}.'
.format(
country_holidays=self.country_holidays,
country_name=country_name,
@ -892,8 +895,8 @@ class Prophet(object):
fourier_order = 0
if name in self.seasonalities:
logger.info(
'Found custom seasonality named "{name}", disabling '
'built-in {name} seasonality.'.format(name=name)
'Found custom seasonality named {name!r}, disabling '
'built-in {name!r} seasonality.'.format(name=name)
)
elif auto_disable:
logger.info(