Example #1
0
    # Developer notes:
    # This class uses dynamic name resolution to convert arbitrary attribute
    # strings into proper column indices. Thus, we should avoid using any
    # internal attributes or method names that have a chance of clashing with
    # user's column names.

    def __init__(self, id_):
        self._id = id_


    def __getattr__(self, name):
        """Retrieve column `name` from the datatable."""
        return self[name]


    def __getitem__(self, item):
        if not isinstance(item, (int, str, slice)):
            from datatable import TypeError, stype, ltype
            if not(item in [bool, int, float, str, object, None] or
                   isinstance(item, (stype, ltype))):
                raise TypeError("Column selector should be an integer, string, "
                                "or slice, not %r" % type(item))
        return Expr(OpCodes.COL, self._id, item)



f = FrameProxy(0)
g = FrameProxy(1)
core._register_function(9, Expr);
Example #2
0
    yield ("string", stype.str64)
    yield (object, stype.obj64)
    yield ("obj", stype.obj64)
    yield ("object", stype.obj64)
    yield ("object64", stype.obj64)

    # "old"-style stypes
    yield ("i1b", stype.bool8)
    yield ("i1i", stype.int8)
    yield ("i2i", stype.int16)
    yield ("i4i", stype.int32)
    yield ("i8i", stype.int64)
    yield ("f4r", stype.float32)
    yield ("f8r", stype.float64)
    yield ("i4s", stype.str32)
    yield ("i8s", stype.str64)
    yield ("p8p", stype.obj64)


def _init_value2members_from(iterator):
    for k, st in iterator:
        assert isinstance(st, stype)
        stype._value2member_map_[k] = st
        ltype._value2member_map_[k] = st.ltype


_init_value2members_from(_additional_stype_members())

core._register_function(2, stype)
core._register_function(3, ltype)
Example #3
0
            TTypeError._handle_(self, *exc_args)
        else:
            print(
                term.color("yellow", self.__class__.__name__ + ": ") +
                term.color("bright_black", str(self)))


def dtwarn(message):
    warnings.warn(message, category=DatatableWarning)


def _showwarning(message, category, filename, lineno, file=None, line=None):
    custom_handler = getattr(category, "_handle_", None)
    if custom_handler:
        custom_handler(message)
    else:
        _default_warnings_hoook(message, category, filename, lineno, file,
                                line)


# Replace the default warnings handler
_default_warnings_hoook = warnings.showwarning
warnings.showwarning = _showwarning

core._register_function(4, TTypeError)
core._register_function(5, TValueError)
core._register_function(6, DatatableWarning)

__all__ = ("typed", "is_type", "U", "TTypeError", "TValueError",
           "TImportError", "DatatableWarning", "dtwarn", "name_type")
Example #4
0
class _DefaultLogger:
    def debug(self, message):
        if message[0] != "[":
            message = "  " + message
        print(term.color("bright_black", message), flush=True)

    def warning(self, message):
        warnings.warn(message, category=FreadWarning)


# os.PathLike interface was added in Python 3.6
_pathlike = (str, bytes, os.PathLike) if hasattr(os, "PathLike") else \
            (str, bytes)

core._register_function(8, fread)

#-------------------------------------------------------------------------------


# Corresponds to RT enum in "reader_parsers.h"
class rtype(enum.Enum):
    rdrop = 0
    rauto = 1
    rbool = 2
    rint = 3
    rint32 = 4
    rint64 = 5
    rfloat = 6
    rfloat32 = 7
    rfloat64 = 8
Example #5
0
    def scalar(self):
        warnings.warn(
            "Method `Frame.scalar()` is deprecated (will be removed in "
            "0.10.0), please use `Frame[0, 0]` istead",
            category=FutureWarning)
        return self[0, 0]

    def append(self):
        warnings.warn(
            "Method `Frame.append()` is deprecated (will be removed in "
            "0.10.0), please use `Frame.rbind()` instead",
            category=FutureWarning)

    def save(self, path, format="jay", _strategy="auto"):
        warnings.warn(
            "Method `Frame.save()` is deprecated (will be removed in "
            "0.10.0), please use `Frame.to_jay()` instead",
            category=FutureWarning)
        if format != "jay":
            raise ValueError("Unknown `format` value: %s" % format)
        return self.to_jay(path, _strategy=_strategy)


#-------------------------------------------------------------------------------
# Global settings
#-------------------------------------------------------------------------------

core._register_function(7, Frame)
core._install_buffer_hooks(Frame)
Example #6
0
        else:
            print(
                term.color("yellow", self.__class__.__name__ + ": ") +
                term.color("bright_black", str(self)))


def dtwarn(message):
    warnings.warn(message, category=DatatableWarning)


def _showwarning(message, category, filename, lineno, file=None, line=None):
    custom_handler = getattr(category, "_handle_", None)
    if custom_handler:
        custom_handler(message)
    else:
        _default_warnings_hoook(message, category, filename, lineno, file,
                                line)


# Replace the default warnings handler
_default_warnings_hoook = warnings.showwarning
warnings.showwarning = _showwarning

core._register_function(4, TTypeError)
core._register_function(5, TValueError)
core._register_function(6, DatatableWarning)
core._register_function(8, InvalidOperationError)

__all__ = ("typed", "is_type", "U", "TTypeError", "TValueError",
           "TImportError", "DatatableWarning", "dtwarn", "name_type")