Created
June 23, 2016 00:39
-
-
Save metasyn/0f7602538bf6593c2935cf949a2b2709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Xander Johnson @metasyn | |
import sys | |
import exec_anaconda | |
try: | |
exec_anaconda.exec_anaconda() | |
except Exception as e: | |
import cexc | |
cexc.abort(e) | |
sys.exit(1) | |
# Import this to get our "chunked" handler | |
from cexc import BaseChunkHandler | |
import cexc | |
import pandas as pd | |
from scipy.stats import anderson | |
class Handler(BaseChunkHandler): | |
def handler(self, metadata, data): | |
"""Get Anderson-Darling test statistic""" | |
raw_args = self.getinfo['searchinfo']['raw_args'] | |
if self.getinfo.get('preview', False): | |
logger.debug('Not running in preview') | |
return {'finished': True} | |
if len(data) != 0: | |
df = pd.DataFrame(data, dtype='float') | |
if len(raw_args) == 0: | |
raise ValueError('Please provide a field name, e.g. | anderson my_field') | |
if raw_args[0] not in df.columns: | |
raise ValueError('Please provide a field name, e.g. | anderson my_field') | |
a = anderson(df[raw_args[0]]) | |
output = pd.DataFrame(a.__dict__).to_dict('records') | |
return({'finished': True}, output) | |
if not metadata.get('finished', False): | |
return {} | |
else: | |
return ({'finished': False}, data) | |
if __name__ == "__main__": | |
Handler().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment