How to use the swat.utils.compat.int32 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 / formatter.py View on Github external
out = a2u(str(float64(value)))
        elif isinstance(value, int64_types):
            if sasfmt and re.match(r'^[df]?\d*\.\d*$', sasfmt):
                out = self._format_numeric(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, int32_types):
            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)):
github sassoftware / python-swat / swat / cas / rest / connection.py View on Github external
elif isinstance(value, dict_types):
            numkeys = [x for x in value.keys() if isinstance(x, int_types)]
            if not numkeys:
                value = _normalize_params(value)
            else:
                value = _normalize_list(value.values())
        elif isinstance(value, items_types):
            value = _normalize_list(value)
        elif isinstance(value, CASTable):
            value = _normalize_params(value.to_params())
        elif isinstance(value, int64_types):
            value = int64(value)
        elif isinstance(value, int32_types):
            value = int32(value)
        elif isinstance(value, int32_types):
            value = int32(value)
        elif isinstance(value, float64_types):
            value = float64(value)
        elif isinstance(value, blob):
            b64data = base64.b64encode(value)
            value = dict(_blob=True, data=a2u(b64data), length=len(value))
        out[key] = value
    return out
github sassoftware / python-swat / swat / formatter.py View on Github external
out = a2u(str(value))
            else:
                try:
                    out = errorcheck(a2u(self._sw_formatter.formatDouble(
                                         float64(value), a2n(sasfmt), int32(width)),
                                         a2n('utf-8')),
                                     self._sw_formatter)
                except SWATError:
                    out = errorcheck(a2u(self._sw_formatter.formatDouble(
                                         float64(value), a2n('best12.'), int32(width)),
                                         a2n('utf-8')),
                                     self._sw_formatter)
        elif isinstance(value, int64_types):
            try:
                out = errorcheck(a2u(self._sw_formatter.formatInt64(
                                     int64(value), a2n(sasfmt), int32(width)),
                                     a2n('utf-8')),
                                 self._sw_formatter)
            except SWATError:
                out = errorcheck(a2u(self._sw_formatter.formatInt64(
                                     int64(value), a2n('best12.'), int32(width)),
                                     a2n('utf-8')),
                                 self._sw_formatter)
        elif isinstance(value, int32_types):
            try:
                try:
                    out = errorcheck(a2u(self._sw_formatter.formatInt32(
                                         int32(value), a2n(sasfmt), int32(width)),
                                         a2n('utf-8')),
                                     self._sw_formatter)
                except SWATError:
                    out = errorcheck(a2u(self._sw_formatter.formatInt32(
github sassoftware / python-swat / swat / cas / transformers.py View on Github external
elif isinstance(item, text_types):
            errorcheck(_sw_values.setString(i, key, a2n(item, 'utf-8')),
                       _sw_values)
            i = i + 1
        elif isinstance(item, binary_types):
            errorcheck(_sw_values.setString(i, key, a2n(item, 'utf-8')),
                       _sw_values)
            i = i + 1
        elif isinstance(item, int64_types):
            errorcheck(_sw_values.setInt64(i, key, int64(item)), _sw_values)
            i = i + 1
        elif isinstance(item, int32_types):
            if item > MAX_INT32 or item < MIN_INT32:
                errorcheck(_sw_values.setInt64(i, key, int64(item)), _sw_values)
            else:
                errorcheck(_sw_values.setInt32(i, key, int32(item)), _sw_values)
            i = i + 1
        elif isinstance(item, float64_types):
            errorcheck(_sw_values.setDouble(i, key, float64(item)), _sw_values)
            i = i + 1
        elif item is nil:
            errorcheck(_sw_values.setNil(i, key), _sw_values)
            i = i + 1
        elif isinstance(item, items_types):
            _sw_sublist = errorcheck(_sw_values.createListAt(
                                     i, key, len(item)), _sw_values)
            j = 0
            for v in item:
                j = set_list_value(_sw_sublist, j, None, v)
            i = i + 1
        elif isinstance(item, (dict_types, ParamManager)):
            if isinstance(item, ParamManager):
github sassoftware / python-swat / swat / cas / datamsghandlers.py View on Github external
elif vrtype == 'NUMERIC' and vtype in ['INT32', 'DATE']:
                if pd.isnull(value):
                    value = get_option('cas.missing.%s' % vtype.lower())
                    warnings.warn(('Missing value found in 32-bit '
                                   + 'integer-based column \'%s\'.\n' % v['name'])
                                   + ('Substituting cas.missing.%s option value (%s).' %
                                      (vtype.lower(), value)),
                                  RuntimeWarning)
                if length > 4:
                    for i in range(int64(length / 4)):
                        errorcheck(self._sw_databuffer.setInt32(row, offset + (i * 4),
                                   int32(transformer(get(value, i, 0)))),
                                   self._sw_databuffer)
                else:
                    errorcheck(self._sw_databuffer.setInt32(row, offset,
                                                            int32(transformer(value))),
                               self._sw_databuffer)
            elif vrtype == 'NUMERIC' and vtype in ['INT64', 'DATETIME', 'TIME']:
                if pd.isnull(value):
                    value = get_option('cas.missing.%s' % vtype.lower())
                    warnings.warn(('Missing value found in 64-bit '
                                   + 'integer-based column \'%s\'.\n' % v['name'])
                                   + ('Substituting cas.missing.%s option value (%s).' %
                                      (vtype.lower(), value)),
                                  RuntimeWarning)
                if length > 8:
                    for i in range(int64(length / 8)):
                        errorcheck(self._sw_databuffer.setInt64(row, offset + (i * 8),
                                   int64(transformer(get(value, i, 0)))),
                                   self._sw_databuffer)
                else:
                    errorcheck(self._sw_databuffer.setInt64(row, offset,
github sassoftware / python-swat / swat / dataframe.py View on Github external
----------
            obj : any
               Arbitrary object to convert

            Returns
            -------
            any
               Python object that JSON encoder will recognize

            '''
            if isinstance(obj, float64_types):
                return float64(obj)
            if isinstance(obj, int64_types):
                return int64(obj)
            if isinstance(obj, (int32_types, bool_types)):
                return int32(obj)
            if isinstance(obj, CASTable):
                return str(obj)
            return json.JSONEncoder.default(self, obj)
github sassoftware / python-swat / swat / cas / rest / connection.py View on Github external
elif value is False:
            pass
        elif isinstance(value, dict_types):
            numkeys = [x for x in value.keys() if isinstance(x, int_types)]
            if not numkeys:
                value = _normalize_params(value)
            else:
                value = _normalize_list(value.values())
        elif isinstance(value, items_types):
            value = _normalize_list(value)
        elif isinstance(value, CASTable):
            value = _normalize_params(value.to_params())
        elif isinstance(value, int64_types):
            value = int64(value)
        elif isinstance(value, int32_types):
            value = int32(value)
        elif isinstance(value, int32_types):
            value = int32(value)
        elif isinstance(value, float64_types):
            value = float64(value)
        elif isinstance(value, blob):
            b64data = base64.b64encode(value)
            value = dict(_blob=True, data=a2u(b64data), length=len(value))
        out[key] = value
    return out
github sassoftware / python-swat / swat / cas / connection.py View on Github external
if typ == 'boolean':
                    if value in [True, False, 1, 0]:
                        errorcheck(self._sw_connection.setBooleanOption(name,
                                                                        value and 1 or 0),
                                   self._sw_connection)
                    else:
                        raise SWATError('%s is not a valid boolean value' % value)
                elif typ == 'string':
                    if isinstance(value, (binary_types, text_types)):
                        errorcheck(self._sw_connection.setStringOption(name, a2n(value)),
                                   self._sw_connection)
                    else:
                        errorcheck(self._sw_connection.setStringOption(name, value),
                                   self._sw_connection)
                elif typ == 'int32':
                    errorcheck(self._sw_connection.setInt32Option(name, int32(value)),
                               self._sw_connection)
                elif typ == 'int64':
                    errorcheck(self._sw_connection.setInt64Option(name, int64(value)),
                               self._sw_connection)
                elif typ == 'double':
                    errorcheck(self._sw_connection.setDoubleOption(name, float64(value)),
                               self._sw_connection)
            except TypeError:
                raise SWATError('%s is not the correct type' % value)
        return True
github sassoftware / python-swat / swat / cas / dbapi.py View on Github external
values = list(parameters)
        for i, item in enumerate(values):
            if item is None or pd.isnull(item):
                values[i] = '.'
            if isinstance(item, text_types):
                values[i] = "'%s'" % item.replace("'", "''")
            elif isinstance(item, binary_types):
                values[i] = b"'%s'" % item.replace("'", "''")
            elif isinstance(item, datetime.datetime):
                values[i] = "'%s'dt" % item.strftime('%d%b%Y:%H:%M:%S')
            elif isinstance(item, datetime.date):
                values[i] = "'%s'd" % item.strftime('%d%b%Y')
            elif isinstance(item, datetime.time):
                values[i] = "'%s't" % item.strftime('%H:%M:%S')
            elif isinstance(item, int32_types):
                values[i] = '%s' % int32(item)
            elif isinstance(item, int64_types):
                values[i] = '%s' % int64(item)
            elif isinstance(item, float64_types):
                values[i] = '%s' % float64(item)
            elif item is True:
                values[i] = '1'
            elif item is False:
                values[i] = '0'
            else:
                raise TypeError('Unrecognized data type: %s' % item)
        if keys:
            return dict(zip(keys, values))
        return tuple(values)