[python] code quality improvements (#1745)

* Add DeepSource config

* Simplify if statement

* Refactor use of dict() with empty literal

* Use set comprehension syntax

* Refactor chained comparison

* Rewrite instances of list literal within set() as set literals

* Add test_slow to class definition
This commit is contained in:
Devdutt Shenoi 2020-12-09 05:05:54 +05:30 committed by GitHub
parent ee592451f2
commit 20f590b726
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 8 deletions

11
.deepsource.toml Normal file
View file

@ -0,0 +1,11 @@
version = 1
test_patterns = ["python/fbprophet/tests/**"]
exclude_patterns = ["R/**", "notebooks/**", "docs/**", "examples/**"]
[[analyzers]]
name = "python"
enabled = true
[analyzers.meta]
runtime_version = "3.x.x"

View file

@ -353,7 +353,7 @@ class Prophet(object):
if n_vals < 2:
standardize = False
if standardize == 'auto':
if set(df[name].unique()) == set([1, 0]):
if set(df[name].unique()) == {1, 0}:
standardize = False # Don't standardize binary variables.
else:
standardize = True

View file

@ -531,7 +531,7 @@ class Malaysia(HolidayBase):
if monthcal[i][5].month == 6:
saturdays.append(monthcal[i][5])
self[saturdays[0]] = name
elif (year >= 2017) and (year <= 2021):
elif 2017 <= year <= 2021:
c = Calendar(firstweekday=MONDAY)
monthcal = c.monthdatescalendar(year, 7)

View file

@ -175,7 +175,7 @@ class CmdStanPyBackend(IStanBackend):
start = 0
end = 0
two_dims = True if len(data.shape) > 1 else False
two_dims = len(data.shape) > 1
for cname in column_names:
parsed = cname.split(".")
@ -235,7 +235,7 @@ class PyStanBackend(IStanBackend):
)
args.update(kwargs)
self.stan_fit = self.model.sampling(**args)
out = dict()
out = {}
for par in self.stan_fit.model_pars:
out[par] = self.stan_fit[par]
# Shape vector parameters
@ -265,7 +265,7 @@ class PyStanBackend(IStanBackend):
else:
raise e
params = dict()
params = {}
for par in self.stan_fit.keys():
params[par] = self.stan_fit[par].reshape((1, -1))

View file

@ -46,12 +46,12 @@ def generate_holidays_file():
all_holidays = []
# class names in holiday packages which are not countries
# Also cut out countries with utf-8 holidays that don't parse to ascii
class_to_exclude = set(['rd', 'BY', 'BG', 'JP', 'RS', 'UA', 'KR'])
class_to_exclude = {'rd', 'BY', 'BG', 'JP', 'RS', 'UA', 'KR'}
class_list2 = inspect.getmembers(hdays_part2, inspect.isclass)
country_set = set([name for name in list(zip(*class_list2))[0] if len(name) == 2])
country_set = {name for name in list(zip(*class_list2))[0] if len(name) == 2}
class_list1 = inspect.getmembers(hdays_part1, inspect.isclass)
country_set1 = set([name for name in list(zip(*class_list1))[0] if len(name) == 2])
country_set1 = {name for name in list(zip(*class_list1))[0] if len(name) == 2}
country_set.update(country_set1)
country_set -= class_to_exclude

View file

@ -70,6 +70,7 @@ class TestCommand(test_command):
('test-runner=', 'r', "Test runner to use"),
('test-slow', 'w', "Test slow suites (default off)"),
]
test_slow = None
def initialize_options(self):
super(TestCommand, self).initialize_options()