How to use the swat.utils.compat.int64 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(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)):
            out = a2u(str(value))
        elif value is None:
            out = a2u('')

        # For CASTable columns in dataframes
        elif isinstance(value, CASTable):
            return a2u(str(value))
github sassoftware / python-swat / swat / cas / utils / datetime.py View on Github external
Examples
    --------
    >>> python2cas_timestamp(datetime.datetime(1970, 1, 1, 12, 0))
    315662400000000

    Returns
    -------
    int
        CAS timestamp

    '''
    delta = pyts - CAS_EPOCH
    if isinstance(delta, type(pd.NaT)):
        # TODO: Change when integers support missing values
        return 0
    return int64((delta.days * 24 * 60 * 60 * 10**6)
                 + (delta.seconds * 10**6) + delta.microseconds)
github sassoftware / python-swat / swat / cas / datamsghandlers.py View on Github external
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,
                                                            int64(transformer(value))),
                               self._sw_databuffer)
            else:
                if length > 8:
                    for i in range(int64(length / 8)):
                        errorcheck(self._sw_databuffer.setDouble(row, offset + (i * 8),
                                   float64(transformer(get(value, i, np.nan)))),
                                   self._sw_databuffer)
                else:
                    errorcheck(self._sw_databuffer.setDouble(row, offset,
                               float64(transformer(value))),
                               self._sw_databuffer)
github sassoftware / python-swat / swat / cas / datamsghandlers.py View on Github external
def identity(val):
            ''' Return `val` '''
            return val

        def get(arr, idx, default=0):
            ''' Return index value or default '''
            try:
                return arr[idx]
            except IndexError:
                return default

        for col in range(len(self.vars)):
            v = self.vars[col]
            offset = int64(v['offset'])
            length = int64(v['length'])
            value = values[col]
            transformer = self.transformers.get(v['name'], identity)
            vtype = v.get('type', '').upper()
            vrtype = v.get('rtype', '').upper()
            if transformer is identity:
                if vtype == 'DATE' and isinstance(value, (datetime.datetime,
                                                          datetime.date)):
                    value = python2cas_date(value)
                elif vtype == 'TIME' and isinstance(value, (datetime.datetime,
                                                            datetime.time)):
                    value = python2cas_time(value)
                elif vtype == 'DATETIME' and isinstance(value, (datetime.date,
                                                                datetime.time,
                                                                datetime.datetime)):
                    value = python2cas_datetime(value)
            if vrtype == 'CHAR' or vtype in ['VARCHAR', 'CHAR', 'BINARY', 'VARBINARY']:
github sassoftware / python-swat / swat / cas / connection.py View on Github external
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 / transformers.py View on Github external
errorcheck(_sw_values.setBoolean(i, key, item and 1 or 0),
                       _sw_values)
            i = i + 1
        elif isinstance(item, blob):
            errorcheck(_sw_values.setBlob(i, key, item), _sw_values)
            i = i + 1
        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)
github sassoftware / python-swat / swat / cas / utils / datetime.py View on Github external
----------
    sts : float
        SAS time.

    Examples
    --------
    >>> sas2cas_time(43200.0)
    43200000000

    Returns
    -------
    int
        CAS time

    '''
    return int64(sts * 10**6)
github sassoftware / python-swat / swat / cas / datamsghandlers.py View on Github external
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,
                                                            int64(transformer(value))),
                               self._sw_databuffer)
            else:
                if length > 8:
                    for i in range(int64(length / 8)):
                        errorcheck(self._sw_databuffer.setDouble(row, offset + (i * 8),
                                   float64(transformer(get(value, i, np.nan)))),
                                   self._sw_databuffer)
                else:
                    errorcheck(self._sw_databuffer.setDouble(row, offset,
                               float64(transformer(value))),
github sassoftware / python-swat / swat / cas / utils / datetime.py View on Github external
----------
    sts : float
        SAS timestamp.

    Examples
    --------
    >>> sas2cas_timestamp(315662400.0)
    315662400000000

    Returns
    -------
    int
        CAS timestamp

    '''
    return int64(sts * 10**6)