Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def messages(self):
''' Return a list of messages '''
messages = []
nmessages = errorcheck(self._sw_response.getNMessages(), self._sw_response)
for i in range(nmessages):
messages.append(errorcheck(
a2u(self._sw_response.getNextMessage(), 'utf-8'), self._sw_response))
return messages
def __init__(self, data=None, index=None, columns=None, dtype=None, copy=False,
name=None, label=None, title=None, formatter=None, attrs=None,
colinfo=None):
super(SASDataFrame, self).__init__(data=data, index=index,
columns=columns, dtype=dtype, copy=copy)
# Only copy column info for columns that exist
self.colinfo = {}
if colinfo:
for col in self.columns:
if col in colinfo:
self.colinfo[col] = colinfo[col]
self.name = a2u(name)
self.label = a2u(label)
self.title = a2u(title)
# TODO: Should attrs be walked and converted to unicode?
self.attrs = attrs
if self.attrs is None:
self.attrs = {}
self.formatter = formatter
if self.formatter is None:
self.formatter = SASFormatter()
# Count used for keeping unique data frame IDs in IPython notebook.
# If a table is rendered more than once, we need to make sure it gets a
# unique ID each time.
self._idcount = 0
def _print_response(text):
''' Print the respnose for debugging '''
sys.stderr.write(a2u(text, 'utf-8'))
sys.stderr.write('\n')
raise SystemError
except SystemError:
raise SWATError(self._sw_error.getLastErrorMessage())
# Set up index origin for error messages
errorcheck(self._sw_connection.setZeroIndexedParameters(), self._sw_connection)
# Get instance structure values from connection layer
self._hostname = errorcheck(
a2u(self._sw_connection.getHostname(), 'utf-8'), self._sw_connection)
self._port = errorcheck(self._sw_connection.getPort(), self._sw_connection)
self._username = errorcheck(
a2u(self._sw_connection.getUsername(), 'utf-8'), self._sw_connection)
self._session = errorcheck(
a2u(self._sw_connection.getSession(), 'utf-8'), self._sw_connection)
self._soptions = errorcheck(
a2u(self._sw_connection.getSOptions(), 'utf-8'), self._sw_connection)
self._protocol = protocol
if name:
self._name = a2u(name)
else:
self._name = 'py-session-%d' % type(self)._sessioncount
type(self)._sessioncount = type(self)._sessioncount + 1
# Caches for action classes and reflection information
self._action_classes = {}
self._action_info = {}
self._actionset_classes = {}
self._actionset_info = {}
# Dictionary of result hook functions
The index of the column
elem : int or long, optional
Optional array index element; None for non-array columns
Returns
-------
:class:`SASColumnSpec` object
'''
name = errorcheck(a2u(_sw_table.getColumnName(col), 'utf-8'), _sw_table)
if elem is not None:
name = name + str(elem + 1)
label = errorcheck(a2u(_sw_table.getColumnLabel(col), 'utf-8'), _sw_table)
dtype = errorcheck(a2u(_sw_table.getColumnType(col), 'utf-8'), _sw_table)
width = errorcheck(_sw_table.getColumnWidth(col), _sw_table)
format = errorcheck(a2u(_sw_table.getColumnFormat(col), 'utf-8'), _sw_table)
size = (1, errorcheck(_sw_table.getColumnArrayNItems(col), _sw_table))
# Get table attributes
attrs = {}
if hasattr(_sw_table, 'getColumnAttributes'):
attrs = _sw_table.getColumnAttributes(col)
else:
while True:
key = errorcheck(_sw_table.getNextColumnAttributeKey(col), _sw_table)
if key is None:
break
typ = errorcheck(_sw_table.getColumnAttributeType(col, a2n(key, 'utf-8')),
_sw_table)
key = a2u(key, 'utf-8')
def __init__(self, name, label=None, dtype=None, width=0, format='',
size=(1, 1), attrs=None):
self.name = a2u(name)
self.label = a2u(label)
self.dtype = a2u(dtype)
self.width = width
self.format = a2u(format)
self.size = size
self.attrs = attrs
if self.attrs is None:
self.attrs = {}
kwargs['formatter'] = SASFormatter(soptions=soptions)
kwargs['name'] = check(a2u(_sw_table.getName(), 'utf-8'), _sw_table)
kwargs['label'] = check(a2u(_sw_table.getLabel(), 'utf-8'), _sw_table)
kwargs['title'] = check(a2u(_sw_table.getTitle(), 'utf-8'), _sw_table)
# get table attributes
attrs = {}
if hasattr(_sw_table, 'getAttributes'):
attrs = _sw_table.getAttributes()
else:
while needattrs:
key = check(a2n(_sw_table.getNextAttributeKey(), 'utf-8'), _sw_table)
if key is None:
break
typ = check(_sw_table.getAttributeType(key), _sw_table)
ukey = a2u(key, 'utf-8')
if typ == 'int32':
attrs[ukey] = check(_sw_table.getInt32Attribute(key), _sw_table)
elif typ == 'int64':
attrs[ukey] = check(_sw_table.getInt64Attribute(key), _sw_table)
elif typ == 'double':
attrs[ukey] = check(_sw_table.getDoubleAttribute(key), _sw_table)
elif typ == 'string':
attrs[ukey] = check(a2u(_sw_table.getStringAttribute(key), 'utf-8'),
_sw_table)
elif typ == 'date':
attrs[ukey] = check(_sw_table.getInt32Attribute(key), _sw_table)
elif typ == 'time':
attrs[ukey] = check(_sw_table.getInt64Attribute(key), _sw_table)
elif typ == 'datetime':
attrs[ukey] = check(_sw_table.getInt64Attribute(key), _sw_table)
elif typ == 'int32-array':
try:
if sasfmt and re.match(r'^[df]?\d*\.\d*$', sasfmt, flags=re.I):
out = self._format_numeric(int32(value), sasfmt, width=width)
elif sasfmt and re.match(r'^(nl)(comma|mny|dollar|euro)\d*\.\d*$', sasfmt, flags=re.I):
out = self._format_numeric(value, sasfmt, width=width, commas=True)
else:
out = a2u(str(int32(value)))
except OverflowError:
if sasfmt and re.match(r'^[df]?\d*\.\d*', sasfmt, flags=re.I):
out = self._format_numeric(int64(value), sasfmt, width=width)
elif sasfmt and re.match(r'^(nl)?(comma|mny|dollar|euro)\d*\.\d*$', sasfmt, flags=re.I):
out = self._format_numeric(value, sasfmt, width=width, commas=True)
else:
out = a2u(str(int64(value)))
elif isinstance(value, text_types):
out = a2u(value)
# TODO: Should binary types ever get here?
elif isinstance(value, binary_types):
out = a2u(value)
elif isinstance(value, bool_types):
out = a2u(str(value))
elif isinstance(value, (datetime.date, datetime.time, datetime.datetime,
Timestamp)):
out = a2u(str(value))
elif value is None:
out = a2u('')
# For CASTable columns in dataframes
elif isinstance(value, CASTable):
return a2u(str(value))
if out is None:
col : int or long
The index of the column
elem : int or long, optional
Optional array index element; None for non-array columns
Returns
-------
:class:`SASColumnSpec` object
'''
name = errorcheck(a2u(_sw_table.getColumnName(col), 'utf-8'), _sw_table)
if elem is not None:
name = name + str(elem + 1)
label = errorcheck(a2u(_sw_table.getColumnLabel(col), 'utf-8'), _sw_table)
dtype = errorcheck(a2u(_sw_table.getColumnType(col), 'utf-8'), _sw_table)
width = errorcheck(_sw_table.getColumnWidth(col), _sw_table)
format = errorcheck(a2u(_sw_table.getColumnFormat(col), 'utf-8'), _sw_table)
size = (1, errorcheck(_sw_table.getColumnArrayNItems(col), _sw_table))
# Get table attributes
attrs = {}
if hasattr(_sw_table, 'getColumnAttributes'):
attrs = _sw_table.getColumnAttributes(col)
else:
while True:
key = errorcheck(_sw_table.getNextColumnAttributeKey(col), _sw_table)
if key is None:
break
typ = errorcheck(_sw_table.getColumnAttributeType(col, a2n(key, 'utf-8')),
_sw_table)