Ejemplo n.º 1
0
    def query_typed(self, exprs):
        """Performs aggregation queries over columns of the table, and returns Python object(s) and types.

        **Examples**

        >>> mean_value, t = kt1.query_typed('C1.stats().mean')

        >>> [hist, counter], [t1, t2] = kt1.query_typed(['HT.hist(50, 80, 10)', 'SEX.counter()'])

        See :py:meth:`.Keytable.query` for more information.

        :param exprs:
        :type exprs: str or list of str

        :rtype: (annotation or list of annotation,  :class:`.Type` or list of :class:`.Type`)
        """


        if isinstance(exprs, list):
            result_list = self._jkt.query(jarray(Env.jvm().java.lang.String, exprs))
            ptypes = [Type._from_java(x._2()) for x in result_list]
            annotations = [ptypes[i]._convert_to_py(result_list[i]._1()) for i in xrange(len(ptypes))]
            return annotations, ptypes

        else:
            result = self._jkt.query(exprs)
            t = Type._from_java(result._2())
            return t._convert_to_py(result._1()), t
Ejemplo n.º 2
0
    def schema(self):
        """Key table schema.

        **Example:**

        Print the key table columns / signatures:

        >>> print(kt1.schema)
        Struct {
            ID: Int,
            HT: Int,
            SEX: String,
            X: Int,
            Z: Int,
            C1: Int,
            C2: Int,
            C3: Int
        }

        :rtype: :class:`.TStruct`
        """

        if self._schema is None:
            self._schema = Type._from_java(self._jkt.signature())
            assert (isinstance(self._schema, TStruct))
        return self._schema
Ejemplo n.º 3
0
    def key_schema(self):
        """
        Returns the signature of the key indexing this matrix.

        :rtype: :class:`.Type`
        """

        if self._key_schema is None:
            self._key_schema = Type._from_java(self._jkm.sampleSignature())
        return self._key_schema
Ejemplo n.º 4
0
    def key_schema(self):
        """
        Returns the signature of the key indexing this matrix.

        :rtype: :class:`.Type`
        """
        from hail.expr import Type
        if self._key_schema is None:
            self._key_schema = Type._from_java(self._jkm.sampleSignature())
        return self._key_schema
Ejemplo n.º 5
0
    def eval_expr_typed(self, expr):
        """Evaluate an expression and return the result as well as its type.

        :param str expr: Expression to evaluate.

        :rtype: (annotation, :class:`.Type`)

        """

        x = self._jhc.eval(expr)
        t = Type._from_java(x._2())
        v = t._convert_to_py(x._1())
        return (v, t)
Ejemplo n.º 6
0
    def eval_expr_typed(self, expr):
        """Evaluate an expression and return the result as well as its type.

        :param str expr: Expression to evaluate.

        :rtype: (annotation, :class:`.Type`)

        """

        x = self._jhc.eval(expr)
        t = Type._from_java(x._2())
        v = t._convert_to_py(x._1())
        return (v, t)
Ejemplo n.º 7
0
    def schema(self):
        """Table schema.

        **Examples**

        >>> print(kt1.schema)

        The ``pprint`` module can be used to print the schema in a more human-readable format:

        >>> from pprint import pprint
        >>> pprint(kt1.schema)

        :rtype: :class:`.TStruct`
        """

        if self._schema is None:
            self._schema = Type._from_java(self._jkt.signature())
            assert (isinstance(self._schema, TStruct))
        return self._schema