Ejemplo n.º 1
0
    def test_empty_stripes(self):
        r = []
        s = self.schema1
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap='stripes', width=80)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[0]--------------------------
i32                         =
floaties                    =
long_column_name_ugh_and_ugh=
long_value                  =
s                           ='''
        self.assertEqual(expected, result)
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap='stripes',
                                              width=80,
                                              with_types=True)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[0]------------------------------
i32:int                         =
floaties:float                  =
long_column_name_ugh_and_ugh:str=
long_value:str                  =
s:str                           ='''
        self.assertEqual(expected, result)
Ejemplo n.º 2
0
 def test_neg_inspect_settings(self):
     try:
         ATable(1, [], 0, format_settings='jump')
     except TypeError:
         pass
     else:
         self.fail("Expected TypeError")
Ejemplo n.º 3
0
    def test_inspection(self):
        result = repr(
            ATable(self.rows1,
                   self.schema1,
                   offset=0,
                   format_settings=Formatting(wrap=2, truncate=40, width=80)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[#]  i32  floaties       long_column_name_ugh_and_ugh
=====================================================
[0]    1  3.14159265358  a
[1]    2    8.014512183  b

[#]  long_value                                s
==================================================
[0]  The sun was shining on the sea,           one
     Shini...
[1]  I'm going down.  Down, down, down, do...  two


[#]  i32  floaties  long_column_name_ugh_and_ugh
================================================
[2]   32       1.0  c

[#]  long_value                                s
=========================================================
[2]  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA  thirty-two'''
        self.assertEqual(expected, result)
Ejemplo n.º 4
0
    def test_line_numbers(self):
        r = [[x, 'b%s' % x, None] for x in xrange(10)]
        s = self.abc_schema
        result = repr(
            ATable(r,
                   s,
                   offset=92,
                   format_settings=Formatting(wrap=5, width=80)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[##]  a  b   c
=================
[92]  0  b0  None
[93]  1  b1  None
[94]  2  b2  None
[95]  3  b3  None
[96]  4  b4  None


[###]  a  b   c
==================
[97]   5  b5  None
[98]   6  b6  None
[99]   7  b7  None
[100]  8  b8  None
[101]  9  b9  None'''
        self.assertEqual(expected, result)
Ejemplo n.º 5
0
    def test_empty(self):
        r = []
        s = self.abc_schema
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap=5, width=80)))
        expected = '''[##]  a  b  c
============='''
        self.assertEqual(expected, result)
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap=5,
                                              width=80,
                                              with_types=True)))
        expected = '''[##]  a:int  b:unicode  c:unicode
================================='''
        self.assertEqual(expected, result)
Ejemplo n.º 6
0
    def test_wrap_long_str_1(self):
        r = [[
            '12345678901234567890123456789012345678901234567890123456789012345678901234567890'
        ]]
        s = [('s', str)]
        settings = Formatting(wrap=5)
        result = repr(ATable(r, s, offset=0, format_settings=settings))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[#]  s
================================================================================
[0]  12345678901234567890123456789012345678901234567890123456789012345678901234567890'''
        self.assertEqual(expected, result)
Ejemplo n.º 7
0
    def test_inspect_nones(self):
        schema = [('s', str), ('v', float)]
        rows = [['super', 1.0095], [None, None]]
        result = repr(
            ATable(rows,
                   schema,
                   offset=0,
                   format_settings=Formatting(wrap=2, round=2, truncate=4)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        self.assertEqual(
            """[#]  s     v
===============
[0]  s...  1.01
[1]  None  None""", result)
Ejemplo n.º 8
0
    def test_simple_stripes(self):
        result = repr(
            ATable(self.two_abc_rows,
                   self.abc_schema,
                   offset=0,
                   format_settings=Formatting(wrap='stripes', margin=10)))
        expected = '''[0]
a=1
b=sixteen_16_abced
c=long
[1]
a=2
b=tiny
c=really really really really long'''
        self.assertEqual(expected, result)
Ejemplo n.º 9
0
def get_inspect(self,
                n=10,
                offset=0,
                columns=None,
                wrap=inspect_settings._unspecified,
                truncate=inspect_settings._unspecified,
                round=inspect_settings._unspecified,
                width=inspect_settings._unspecified,
                margin=inspect_settings._unspecified,
                with_types=inspect_settings._unspecified):
    """Returns an ATable object representing the table inspect --see frame.inspect()"""
    from sparktk.frame.ops.take import take_rich
    format_settings = inspect_settings.copy(wrap, truncate, round, width,
                                            margin, with_types)
    result = take_rich(self, n, offset, columns)
    return ATable(result.data,
                  result.schema,
                  offset=offset,
                  format_settings=format_settings)
Ejemplo n.º 10
0
 def r(value, num_digits):
     return ATable.get_rounder(float, num_digits)(value)
Ejemplo n.º 11
0
 def r(value, num_digits):
     return ATable.get_rounder(float, num_digits)(value)
Ejemplo n.º 12
0
def inspect(self,
            n=10,
            offset=0,
            columns=None,
            wrap=inspect_settings._unspecified,
            truncate=inspect_settings._unspecified,
            round=inspect_settings._unspecified,
            width=inspect_settings._unspecified,
            margin=inspect_settings._unspecified,
            with_types=inspect_settings._unspecified):
    """
    Pretty-print of the frame data

    Essentially returns a string, but technically returns a RowInspection object which renders a string.
    The RowInspection object naturally converts to a str when needed, like when printed or when displayed
    by python REPL (i.e. using the object's __repr__).  If running in a script and want the inspect output
    to be printed, then it must be explicitly printed, then `print frame.inspect()`

    Parameters
    ----------
    :param n: (Optional[int]) The number of rows to print
    :param offset: (Optional[int]) The number of rows to skip before printing.
    :param columns: (Optional[List[str]]) Filter columns to be included.  By default, all columns are included.
    :param wrap: (Optional[int or 'stripes']) If set to 'stripes' then inspect prints rows in stripes; if set to an
                 integer N, rows will be printed in clumps of N columns, where the columns are wrapped.
    :param truncate: (Optional[int]) If set to integer N, all strings will be truncated to length N, including all
                     tagged ellipses.
    :param round: (Optional[int]) If set to integer N, all floating point numbers will be rounded and truncated to
                  N digits.
    :param width: (Optional[int]) If set to integer N, the print out will try to honor a max line width of N.
    :param margin: (Optional[int]) Applies to 'stripes' mode only.  If set to integer N, the margin for printing names
                   in a stripe will be limited to N characters.
    :param with_types: (Optinoal[bool]) If set to True, header will include the data_type of each column.
    :return: (RowsInspection) An object which naturally converts to a pretty-print string.

    Examples
    --------
    To look at the first 4 rows of data in a frame:

    <skip>
        >>> frame.inspect(4)
        [#]  animal    name    age  weight
        ==================================
        [0]  human     George    8   542.5
        [1]  human     Ursula    6   495.0
        [2]  ape       Ape      41   400.0
        [3]  elephant  Shep      5  8630.0
    </skip>

    # For other examples, see :ref:`example_frame.inspect`.

    Note: if the frame data contains unicode characters, this method may raise a Unicode exception when
    running in an interactive REPL or otherwise which triggers the standard python repr().  To get around
    this problem, explicitly print the unicode of the returned object:

    <skip>
        >>> print unicode(frame.inspect())
    </skip>


    **Global Settings**

    If not specified, the arguments that control formatting receive default values from
    'sparktk.inspect_settings'.  Make changes there to affect all calls to inspect.

        >>> import sparktk
        >>> sparktk.inspect_settings
        wrap             20
        truncate       None
        round          None
        width            80
        margin         None
        with_types    False
        >>> sparktk.inspect_settings.width = 120  # changes inspect to use 120 width globally
        >>> sparktk.inspect_settings.truncate = 16  # changes inspect to always truncate strings to 16 chars
        >>> sparktk.inspect_settings
        wrap             20
        truncate         16
        round          None
        width           120
        margin         None
        with_types    False
        >>> sparktk.inspect_settings.width = None  # return value back to default
        >>> sparktk.inspect_settings
        wrap             20
        truncate         16
        round          None
        width            80
        margin         None
        with_types    False
        >>> sparktk.inspect_settings.reset()  # set everything back to default
        >>> sparktk.inspect_settings
        wrap             20
        truncate       None
        round          None
        width            80
        margin         None
        with_types    False

    """
    from sparktk.frame.ops.take import take_rich
    format_settings = inspect_settings.copy(wrap, truncate, round, width,
                                            margin, with_types)
    result = take_rich(self, n, offset, columns)
    return ATable(result.data,
                  result.schema,
                  offset=offset,
                  format_settings=format_settings)