Skip to content

Commit

Permalink
Ran black on project (#379)
Browse files Browse the repository at this point in the history
* Ran black on project

* yaml flake8 conf

* newline

* Removed extraneous whitespace
  • Loading branch information
WillAyd authored and 0golovatyi committed Dec 18, 2019
1 parent 109148c commit 26b34d9
Show file tree
Hide file tree
Showing 60 changed files with 2,338 additions and 2,186 deletions.
4 changes: 4 additions & 0 deletions .pep8speaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# File : .pep8speaks.yml

flake8:
max-line-length: 88
127 changes: 63 additions & 64 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,105 +1,104 @@
'''Web server Tableau uses to run Python scripts.
"""Web server Tableau uses to run Python scripts.
TabPy (the Tableau Python Server) is an external service implementation
which expands Tableau's capabilities by allowing users to execute Python
scripts and saved functions via Tableau's table calculations.
'''
"""

import os
from setuptools import setup, find_packages


DOCLINES = (__doc__ or '').split('\n')
DOCLINES = (__doc__ or "").split("\n")


def setup_package():
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
name='tabpy',
version=read('tabpy/VERSION'),
name="tabpy",
version=read("tabpy/VERSION"),
description=DOCLINES[0],
long_description='\n'.join(DOCLINES[1:]) + '\n' + read('CHANGELOG'),
long_description_content_type='text/markdown',
url='https://github.com/tableau/TabPy',
author='Tableau',
author_email='github@tableau.com',
maintainer='Tableau',
maintainer_email='github@tableau.com',
download_url='https://pypi.org/project/tabpy',
long_description="\n".join(DOCLINES[1:]) + "\n" + read("CHANGELOG"),
long_description_content_type="text/markdown",
url="https://github.com/tableau/TabPy",
author="Tableau",
author_email="github@tableau.com",
maintainer="Tableau",
maintainer_email="github@tableau.com",
download_url="https://pypi.org/project/tabpy",
project_urls={
"Bug Tracker": "https://github.com/tableau/TabPy/issues",
"Documentation": "https://tableau.github.io/TabPy/",
"Source Code": "https://github.com/tableau/TabPy",
},
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Information Analysis',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Operating System :: MacOS'
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.6",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Information Analysis",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS",
],
platforms=['Windows', 'Linux', 'Mac OS-X', 'Unix'],
keywords=['tabpy tableau'],
packages=find_packages(
exclude=['docs', 'misc', 'tests']),
platforms=["Windows", "Linux", "Mac OS-X", "Unix"],
keywords=["tabpy tableau"],
packages=find_packages(exclude=["docs", "misc", "tests"]),
package_data={
'tabpy': [
'VERSION',
'tabpy_server/state.ini.template',
'tabpy_server/static',
'tabpy_server/common/default.conf'
"tabpy": [
"VERSION",
"tabpy_server/state.ini.template",
"tabpy_server/static",
"tabpy_server/common/default.conf",
]
},
python_requires='>=3.6',
license='MIT',
python_requires=">=3.6",
license="MIT",
# Note: many of these required packages are included in base python
# but are listed here because different linux distros use custom
# python installations. And users can remove packages at any point
install_requires=[
'backports_abc',
'cloudpickle',
'configparser',
'decorator',
'future',
'genson',
'jsonschema',
'pyopenssl',
'python-dateutil',
'requests',
'singledispatch',
'six',
'tornado',
'urllib3<1.25,>=1.21.1'
"backports_abc",
"cloudpickle",
"configparser",
"decorator",
"future",
"genson",
"jsonschema",
"pyopenssl",
"python-dateutil",
"requests",
"singledispatch",
"six",
"tornado",
"urllib3<1.25,>=1.21.1",
],
entry_points={
'console_scripts': [
'tabpy=tabpy.tabpy:main',
'tabpy-deploy-models=tabpy.models.deploy_models:main',
'tabpy-user-management=tabpy.utils.user_management:main'
"console_scripts": [
"tabpy=tabpy.tabpy:main",
"tabpy-deploy-models=tabpy.models.deploy_models:main",
"tabpy-user-management=tabpy.utils.user_management:main",
],
},
setup_requires=['pytest-runner'],
setup_requires=["pytest-runner"],
tests_require=[
'mock',
'nltk',
'numpy',
'pandas',
'pytest',
'scipy',
'sklearn',
'textblob'
"mock",
"nltk",
"numpy",
"pandas",
"pytest",
"scipy",
"sklearn",
"textblob",
],
test_suite='pytest'
test_suite="pytest",
)


if __name__ == '__main__':
if __name__ == "__main__":
setup_package()
24 changes: 11 additions & 13 deletions tabpy/models/deploy_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,38 @@


def install_dependencies(packages):
pip_arg = ['install'] + packages + ['--no-cache-dir']
if hasattr(pip, 'main'):
pip_arg = ["install"] + packages + ["--no-cache-dir"]
if hasattr(pip, "main"):
pip.main(pip_arg)
else:
pip._internal.main(pip_arg)


def main():
install_dependencies(['sklearn', 'pandas', 'numpy',
'textblob', 'nltk', 'scipy'])
print('==================================================================')
install_dependencies(["sklearn", "pandas", "numpy", "textblob", "nltk", "scipy"])
print("==================================================================")
# Determine if we run python or python3
if platform.system() == 'Windows':
py = 'python'
if platform.system() == "Windows":
py = "python"
else:
py = 'python3'
py = "python3"

if len(sys.argv) > 1:
config_file_path = sys.argv[1]
else:
config_file_path = setup_utils.get_default_config_file_path()
print(f'Using config file at {config_file_path}')
print(f"Using config file at {config_file_path}")
port, auth_on, prefix = setup_utils.parse_config(config_file_path)
if auth_on:
auth_args = setup_utils.get_creds()
else:
auth_args = []

directory = str(Path(__file__).resolve().parent / 'scripts')
directory = str(Path(__file__).resolve().parent / "scripts")
# Deploy each model in the scripts directory
for filename in os.listdir(directory):
subprocess.run([py, f'{directory}/{filename}', config_file_path]
+ auth_args)
subprocess.run([py, f"{directory}/{filename}", config_file_path] + auth_args)


if __name__ == '__main__':
if __name__ == "__main__":
main()
11 changes: 4 additions & 7 deletions tabpy/models/scripts/ANOVA.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@


def anova(_arg1, _arg2, *_argN):
'''
"""
ANOVA is a statistical hypothesis test that is used to compare
two or more group means for equality.For more information on
the function and how to use it please refer to tabpy-tools.md
'''
"""

cols = [_arg1, _arg2] + list(_argN)
for col in cols:
Expand All @@ -18,8 +18,5 @@ def anova(_arg1, _arg2, *_argN):
return p_value


if __name__ == '__main__':
setup_utils.deploy_model(
'anova',
anova,
'Returns the p-value form an ANOVA test')
if __name__ == "__main__":
setup_utils.deploy_model("anova", anova, "Returns the p-value form an ANOVA test")
24 changes: 11 additions & 13 deletions tabpy/models/scripts/PCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@


def PCA(component, _arg1, _arg2, *_argN):
'''
"""
Principal Component Analysis is a technique that extracts the key
distinct components from a high dimensional space whie attempting
to capture as much of the variance as possible. For more information
on the function and how to use it please refer to tabpy-tools.md
'''
"""
cols = [_arg1, _arg2] + list(_argN)
encodedCols = []
labelEncoder = LabelEncoder()
oneHotEncoder = OneHotEncoder(categories='auto', sparse=False)
oneHotEncoder = OneHotEncoder(categories="auto", sparse=False)

for col in cols:
if isinstance(col[0], (int, float)):
Expand All @@ -27,8 +27,10 @@ def PCA(component, _arg1, _arg2, *_argN):
encodedCols.append(intCol.astype(int))
else:
if len(set(col)) > 25:
print('ERROR: Non-numeric arguments cannot have more than '
'25 unique values')
print(
"ERROR: Non-numeric arguments cannot have more than "
"25 unique values"
)
raise ValueError
integerEncoded = labelEncoder.fit_transform(array(col))
integerEncoded = integerEncoded.reshape(len(col), 1)
Expand All @@ -38,11 +40,10 @@ def PCA(component, _arg1, _arg2, *_argN):

dataDict = {}
for i in range(len(encodedCols)):
dataDict[f'col{1 + i}'] = list(encodedCols[i])
dataDict[f"col{1 + i}"] = list(encodedCols[i])

if component <= 0 or component > len(dataDict):
print('ERROR: Component specified must be >= 0 and '
'<= number of arguments')
print("ERROR: Component specified must be >= 0 and " "<= number of arguments")
raise ValueError

df = pd.DataFrame(data=dataDict, dtype=float)
Expand All @@ -55,8 +56,5 @@ def PCA(component, _arg1, _arg2, *_argN):
return pcaComponents[:, component - 1].tolist()


if __name__ == '__main__':
setup_utils.deploy_model(
'PCA',
PCA,
'Returns the specified principal component')
if __name__ == "__main__":
setup_utils.deploy_model("PCA", PCA, "Returns the specified principal component")
27 changes: 14 additions & 13 deletions tabpy/models/scripts/SentimentAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,48 @@


import ssl

_ctx = ssl._create_unverified_context
ssl._create_default_https_context = _ctx


nltk.download('vader_lexicon')
nltk.download('punkt')
nltk.download("vader_lexicon")
nltk.download("punkt")


def SentimentAnalysis(_arg1, library='nltk'):
'''
def SentimentAnalysis(_arg1, library="nltk"):
"""
Sentiment Analysis is a procedure that assigns a score from -1 to 1
for a piece of text with -1 being negative and 1 being positive. For
more information on the function and how to use it please refer to
tabpy-tools.md
'''
"""
if not (isinstance(_arg1[0], str)):
raise TypeError

supportedLibraries = {'nltk', 'textblob'}
supportedLibraries = {"nltk", "textblob"}

library = library.lower()
if library not in supportedLibraries:
raise ValueError

scores = []
if library == 'nltk':
if library == "nltk":
sid = SentimentIntensityAnalyzer()
for text in _arg1:
sentimentResults = sid.polarity_scores(text)
score = sentimentResults['compound']
score = sentimentResults["compound"]
scores.append(score)
elif library == 'textblob':
elif library == "textblob":
for text in _arg1:
currScore = TextBlob(text)
scores.append(currScore.sentiment.polarity)
return scores


if __name__ == '__main__':
if __name__ == "__main__":
setup_utils.deploy_model(
'Sentiment Analysis',
"Sentiment Analysis",
SentimentAnalysis,
'Returns a sentiment score between -1 and 1 for '
'a given string')
"Returns a sentiment score between -1 and 1 for " "a given string",
)
11 changes: 4 additions & 7 deletions tabpy/models/scripts/tTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@


def ttest(_arg1, _arg2):
'''
"""
T-Test is a statistical hypothesis test that is used to compare
two sample means or a sample’s mean against a known population mean.
For more information on the function and how to use it please refer
to tabpy-tools.md
'''
"""
# one sample test with mean
if len(_arg2) == 1:
test_stat, p_value = stats.ttest_1samp(_arg1, _arg2)
Expand All @@ -35,8 +35,5 @@ def ttest(_arg1, _arg2):
return p_value


if __name__ == '__main__':
setup_utils.deploy_model(
'ttest',
ttest,
'Returns the p-value form a t-test')
if __name__ == "__main__":
setup_utils.deploy_model("ttest", ttest, "Returns the p-value form a t-test")
Loading

0 comments on commit 26b34d9

Please sign in to comment.