How to use the swat.utils.config.register_option function in swat

To help you get started, we’ve selected a few swat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sassoftware / python-swat / swat / config.py View on Github external
return os.environ['TKPATH']

    import sys
    platform = 'linux'
    if sys.platform.lower().startswith('win'):
        platform = 'win'
    elif sys.platform.lower().startswith('darwin'):
        platform = 'mac'

    # See if the lib// directory has files in it.
    path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib', platform))
    if os.path.isdir(path) and len(os.listdir(path)) > 20:
        return path


register_option('tkpath', 'string', set_tkpath, _initialize_tkpath(),
                'Displays the path for SAS TK components.  This is determined\n'
                'when SWAT is imported.  By default, it points to the platform\n'
                'directory under the swat.lib module.  It can be overridden by\n'
                'setting a TKPATH environment variable.')

#
# General options
#

register_option('encoding_errors', 'string', check_string, 'strict',
                'Specifies the error handler for encoding and decoding errors in\n'
                'handling strings.  Possible values are given in the Python\n'
                'documentation.  Typical values are strict, ignore, replace, or\n'
                'xmlcharrefreplace.')

register_option('interactive_mode', 'boolean', check_boolean, True,
github sassoftware / python-swat / swat / config.py View on Github external
#

register_option('cas.print_messages', 'boolean', check_boolean, True,
                'Indicates whether or not CAS response messages should be printed.')

register_option('cas.trace_actions', 'boolean', check_boolean, False,
                'Indicates whether or not CAS action names and parameters should\n'
                'be printed.  This can be helpful in debugging incorrect action\n'
                'parameters.')

register_option('cas.trace_ui_actions', 'boolean', check_boolean, False,
                'Indicates whether or not CAS action names and parameters from\n'
                'actions invoked by the interface itself. should be printed.\n'
                'This option is only honored if cas.trace_actions is also enabled.')

register_option('cas.hostname', 'string', check_string,
                'localhost',
                'Specifies the hostname for the CAS server.',
                environ='CASHOST')

register_option('cas.port', 'int', check_int, 0,
                'Sets the port number for the CAS server.',
                environ='CASPORT')

register_option('cas.protocol', 'string',
                functools.partial(check_string,
                                  valid_values=['auto', 'cas', 'http', 'https']),
                'auto',
                'Communication protocol for talking to CAS server.\n'
                'The value of "auto" will try to auto-detect the type.\n'
                'Using "http" or "https" will use the REST interface.',
                environ='CASPROTOCOL')
github sassoftware / python-swat / swat / config.py View on Github external
register_option('cas.trace_ui_actions', 'boolean', check_boolean, False,
                'Indicates whether or not CAS action names and parameters from\n'
                'actions invoked by the interface itself. should be printed.\n'
                'This option is only honored if cas.trace_actions is also enabled.')

register_option('cas.hostname', 'string', check_string,
                'localhost',
                'Specifies the hostname for the CAS server.',
                environ='CASHOST')

register_option('cas.port', 'int', check_int, 0,
                'Sets the port number for the CAS server.',
                environ='CASPORT')

register_option('cas.protocol', 'string',
                functools.partial(check_string,
                                  valid_values=['auto', 'cas', 'http', 'https']),
                'auto',
                'Communication protocol for talking to CAS server.\n'
                'The value of "auto" will try to auto-detect the type.\n'
                'Using "http" or "https" will use the REST interface.',
                environ='CASPROTOCOL')


def check_severity(sev):
    ''' Make sure the severity is None or an int '''
    if sev is None:
        return None
    return check_int(sev, maximum=2, minimum=0)
github sassoftware / python-swat / swat / config.py View on Github external
warnings.warn('max_rows_fetched does not affect explicit calls to the '
                  'table.fetch action, only hidden fetches in methods such '
                  'as head, tail, plot, etc.', OptionWarning)
    return check_int(val)


register_option('cas.dataset.max_rows_fetched', 'int', check_max_rows_fetched, 10000,
                'The maximum number of rows to fetch with methods that use\n'
                'the table.fetch action in the background (i.e. the head, tail,\n'
                'values, etc. of CASTable).\n'
                'NOTE: This does not affect explicit calls to the table.fetch action.\n'
                '      Using the maxrows=, to=, and from= action parameters will\n'
                '      return any number of rows, but in batches (e.g., Fetch1, \n'
                '      Fetch2, etc.).')

register_option('cas.dataset.bygroup_columns', 'string',
                functools.partial(check_string,
                                  valid_values=['none', 'raw', 'formatted', 'both']),
                'formatted',
                'CAS returns by grouping information as metadata on a table.\n'
                'This metadata can be used to construct columns in the output table.\n'
                'The possible values of this option are:\n'
                '    none : Do not convert metadata to columns\n'
                '    raw  : Use the raw (i.e., unformatted) values\n'
                '    formatted : Use the formatted value.  This is the actual value\n'
                '                used to do the grouping\n'
                '    both : Add columns for both raw and formatted')

register_option('cas.dataset.bygroup_formatted_suffix', 'string', check_string, '_f',
                'Suffix to use on the formatted column name when both raw and\n'
                'formatted by group colunms are added.')
github sassoftware / python-swat / swat / config.py View on Github external
register_option('cas.dataset.date_formats', 'string or list of strings',
                check_string_list,
                ['B8601DA', 'DATE', 'DAY', 'DDMMYY.?', 'DOWNAME', 'E8601DA',
                 'EURDFDD', 'EURDFDE', 'EURDFDN', 'EURDFDWN', 'EURDFMN', 'EURDFMY',
                 'EURDFWDX', 'EURDFWKX', 'HDATE', 'HEBDATE', 'JULDAY', 'JULIAN',
                 'MINGUO', 'MMDDYY.?', 'MMYY.?', 'MONNAME', 'MONTH', 'MONYY',
                 'NENGO', 'NLDATE[A-Z]*', 'PDJULG', 'PDJULI', 'QTRR', 'QTR',
                 'WEEKDATE', 'WEEKDATX', 'WEEKDAY', 'WEEKU', 'WEEKV', 'WEEK',
                 'WORDDATE', 'WORDDATX', 'YEAR', 'YYMMDD.?', 'YYMM.?', 'YYMM.?',
                 'YYMON', 'YYQR.?', 'YYQZ', 'YYQ', 'YYQ.?', 'YYWEEKU', 'YYWEEKV',
                 'YYWEEKW'],
                'Format names used to indicate the column should be converted\n'
                'to a Python date object.')

register_option('cas.dataset.datetime_formats', 'string or list of strings',
                check_string_list,
                ['B8601DN', 'B8601DT', 'B8601DX', 'B8601DZ', 'B8601LX', 'B8601LZ',
                 'B8601TM', 'B8601TX', 'B8601TZ', 'DATEAMPM', 'DATETIME', 'DTDATE',
                 'DTMONYY', 'DTWEEKV', 'DTWKDATX', 'DTYEAR', 'DTYYQC', 'E8601DN',
                 'E8601DT', 'E8601DX', 'E8601DZ', 'E8601LX', 'E8601LZ', 'E8601TM',
                 'E8601TX', 'E8601TZ', 'EURDFDT', 'HHMM', 'HOUR', 'MDYAMPM', 'MMSS',
                 'NLDATM[A-Z]*', 'NLTIMAP', 'NLTIME', 'TIMEAMPM', 'TIME', 'TOD'],
                'Format names used to indicate the column should be converted\n'
                'to a Python datetime object.')

register_option('cas.dataset.index_name', 'string or list of strings',
                check_string_list, '_Index_',
                'The name or names of the columns to be automatically converted\n'
                'to the index.')

register_option('cas.dataset.drop_index_name', 'boolean', check_boolean, True,
github sassoftware / python-swat / swat / config.py View on Github external
'YYWEEKW'],
                'Format names used to indicate the column should be converted\n'
                'to a Python date object.')

register_option('cas.dataset.datetime_formats', 'string or list of strings',
                check_string_list,
                ['B8601DN', 'B8601DT', 'B8601DX', 'B8601DZ', 'B8601LX', 'B8601LZ',
                 'B8601TM', 'B8601TX', 'B8601TZ', 'DATEAMPM', 'DATETIME', 'DTDATE',
                 'DTMONYY', 'DTWEEKV', 'DTWKDATX', 'DTYEAR', 'DTYYQC', 'E8601DN',
                 'E8601DT', 'E8601DX', 'E8601DZ', 'E8601LX', 'E8601LZ', 'E8601TM',
                 'E8601TX', 'E8601TZ', 'EURDFDT', 'HHMM', 'HOUR', 'MDYAMPM', 'MMSS',
                 'NLDATM[A-Z]*', 'NLTIMAP', 'NLTIME', 'TIMEAMPM', 'TIME', 'TOD'],
                'Format names used to indicate the column should be converted\n'
                'to a Python datetime object.')

register_option('cas.dataset.index_name', 'string or list of strings',
                check_string_list, '_Index_',
                'The name or names of the columns to be automatically converted\n'
                'to the index.')

register_option('cas.dataset.drop_index_name', 'boolean', check_boolean, True,
                'If True, the name of the index is set to None.')

register_option('cas.dataset.index_adjustment', 'int', check_int, -1,
                'Adjustment to the index specified by cas.dataset.index.\n'
                'This can be used to adjust SAS 1-based index data sets to\n'
                '0-based Pandas DataFrames.')


def check_max_rows_fetched(val):
    ''' Check the max_rows_fetched value and print warning '''
    warnings.warn('max_rows_fetched does not affect explicit calls to the '
github sassoftware / python-swat / swat / config.py View on Github external
'The possible values of this option are:\n'
                '    none : Do not convert metadata to columns\n'
                '    raw  : Use the raw (i.e., unformatted) values\n'
                '    formatted : Use the formatted value.  This is the actual value\n'
                '                used to do the grouping\n'
                '    both : Add columns for both raw and formatted')

register_option('cas.dataset.bygroup_formatted_suffix', 'string', check_string, '_f',
                'Suffix to use on the formatted column name when both raw and\n'
                'formatted by group colunms are added.')

register_option('cas.dataset.bygroup_collision_suffix', 'string', check_string, '_by',
                'Suffix to use on the By group column name when a By group column\n'
                'is also included as a data column.')

register_option('cas.dataset.bygroup_as_index', 'boolean', check_boolean, True,
                'If True, any by group columns are set as the DataFrame index.')

register_option('cas.dataset.bygroup_casout_threshold', 'int', check_int, 25000,
                'When using pandas DataFrame APIs for simple statistics (e.g. \n'
                'min, max, quantiles, etc.), if the number of By groupings is\n'
                'greater than this threshold, a CAS table of results is created\n'
                'rather than returning the results to the client.  Note that the\n'
                'number of by groups is only estimated based on the product of the\n'
                'cardinality of each by group variable.')

#
# Debugging options
#

register_option('cas.debug.requests', 'boolean', check_boolean, False,
                'Display requested URL when accessing REST interface.')
github sassoftware / python-swat / swat / config.py View on Github external
'Indicates the CAS action severity level at which an exception\n'
                'should be raised.  None means that no exception should be raised.\n'
                '1 would raise exceptions on warnings.  2 would raise exceptions\n'
                'on errors.')

#
# Integer missing value substitutions
#

register_option('cas.missing.int64', 'int', check_int, -2**(64 - 1),
                'Sets substitution value for int64 missing values.')

register_option('cas.missing.int32', 'int', check_int, -2**(32 - 1),
                'Sets substitution value for int32 missing values.')

register_option('cas.missing.date', 'int', check_int, -2**(32 - 1),
                'Sets substitution value for date missing values.')

register_option('cas.missing.time', 'int', check_int, -2**(64 - 1),
                'Sets substitution value for time missing values.')

register_option('cas.missing.datetime', 'int', check_int, -2**(64 - 1),
                'Sets substitution value for datetime missing values.')

#
# Tabular data options
#

register_option('cas.dataset.format', 'string',
                functools.partial(check_string,
                                  valid_values=['dataframe:sas', 'dataframe',
                                                'dict', 'dict:list',
github sassoftware / python-swat / swat / config.py View on Github external
'DTMONYY', 'DTWEEKV', 'DTWKDATX', 'DTYEAR', 'DTYYQC', 'E8601DN',
                 'E8601DT', 'E8601DX', 'E8601DZ', 'E8601LX', 'E8601LZ', 'E8601TM',
                 'E8601TX', 'E8601TZ', 'EURDFDT', 'HHMM', 'HOUR', 'MDYAMPM', 'MMSS',
                 'NLDATM[A-Z]*', 'NLTIMAP', 'NLTIME', 'TIMEAMPM', 'TIME', 'TOD'],
                'Format names used to indicate the column should be converted\n'
                'to a Python datetime object.')

register_option('cas.dataset.index_name', 'string or list of strings',
                check_string_list, '_Index_',
                'The name or names of the columns to be automatically converted\n'
                'to the index.')

register_option('cas.dataset.drop_index_name', 'boolean', check_boolean, True,
                'If True, the name of the index is set to None.')

register_option('cas.dataset.index_adjustment', 'int', check_int, -1,
                'Adjustment to the index specified by cas.dataset.index.\n'
                'This can be used to adjust SAS 1-based index data sets to\n'
                '0-based Pandas DataFrames.')


def check_max_rows_fetched(val):
    ''' Check the max_rows_fetched value and print warning '''
    warnings.warn('max_rows_fetched does not affect explicit calls to the '
                  'table.fetch action, only hidden fetches in methods such '
                  'as head, tail, plot, etc.', OptionWarning)
    return check_int(val)


register_option('cas.dataset.max_rows_fetched', 'int', check_max_rows_fetched, 10000,
                'The maximum number of rows to fetch with methods that use\n'
                'the table.fetch action in the background (i.e. the head, tail,\n'
github sassoftware / python-swat / swat / config.py View on Github external
register_option('cas.dataset.auto_castable', 'boolean', check_boolean, True,
                'Should a column of CASTable objects be automatically\n'
                'created if a CASLib and CAS table name are columns in the data?\n'
                'NOTE: This applies to all except the \'tuples\' format.')


def check_string_list(val):
    ''' Verify that value is a string or list of strings '''
    if isinstance(val, (list, set, tuple)):
        for item in val:
            check_string(item)
        return val
    return check_string(val)


register_option('cas.dataset.date_formats', 'string or list of strings',
                check_string_list,
                ['B8601DA', 'DATE', 'DAY', 'DDMMYY.?', 'DOWNAME', 'E8601DA',
                 'EURDFDD', 'EURDFDE', 'EURDFDN', 'EURDFDWN', 'EURDFMN', 'EURDFMY',
                 'EURDFWDX', 'EURDFWKX', 'HDATE', 'HEBDATE', 'JULDAY', 'JULIAN',
                 'MINGUO', 'MMDDYY.?', 'MMYY.?', 'MONNAME', 'MONTH', 'MONYY',
                 'NENGO', 'NLDATE[A-Z]*', 'PDJULG', 'PDJULI', 'QTRR', 'QTR',
                 'WEEKDATE', 'WEEKDATX', 'WEEKDAY', 'WEEKU', 'WEEKV', 'WEEK',
                 'WORDDATE', 'WORDDATX', 'YEAR', 'YYMMDD.?', 'YYMM.?', 'YYMM.?',
                 'YYMON', 'YYQR.?', 'YYQZ', 'YYQ', 'YYQ.?', 'YYWEEKU', 'YYWEEKV',
                 'YYWEEKW'],
                'Format names used to indicate the column should be converted\n'
                'to a Python date object.')

register_option('cas.dataset.datetime_formats', 'string or list of strings',
                check_string_list,
                ['B8601DN', 'B8601DT', 'B8601DX', 'B8601DZ', 'B8601LX', 'B8601LZ',