Example #1
0
class Repr(object):

    goal_time = 0.2

    def setup(self):
        nrows = 10000
        data = np.random.randn(nrows, 10)
        arrays = np.tile(np.random.randn(3, int(nrows / 100)), 100)
        idx = MultiIndex.from_arrays(arrays)
        self.df3 = DataFrame(data, index=idx)
        self.df4 = DataFrame(data, index=np.random.randn(nrows))
        self.df_tall = DataFrame(np.random.randn(nrows, 10))
        self.df_wide = DataFrame(np.random.randn(10, nrows))

    def time_html_repr_trunc_mi(self):
        self.df3._repr_html_()

    def time_html_repr_trunc_si(self):
        self.df4._repr_html_()

    def time_repr_tall(self):
        repr(self.df_tall)

    def time_frame_repr_wide(self):
        repr(self.df_wide)
 def _repr_html_(self, *args, **kwargs):
    """ Ipython Notebook HTML appearance basically.  This only generates
    the colored header; under the hood, self._frame._repr_html_ calculates
    the table, including the proper size for optimal viewing and so on.
    """
    # Change output based on Spectra vs. Spectrum
    obj = self._frame
    
    # Series doesn't have _repr_html, so actually call DF's
    if isinstance(obj, Series):
       obj = DataFrame(obj, columns=[self.specifier])
 
    # Call DataFrame _repr_html
    dfhtml = obj._repr_html_(*args, **kwargs)
    return ('<h4>%s</h4>' % ''.join(self._header_html)) +'<br>'+ dfhtml
Example #3
0
def spectra_to_html(spectra, *args, **kwargs):
   """ HTML representation used for Spectra and Spectrum for ipython notebooks"""

   delim = '&nbsp;' * 8

   if spectra.ndim > 1:
      colorshape = '<font color="#0000CD">(%s X %s)</font>' % (spectra.shape)
   else:
      colorshape = '<font color="#0000CD"> (%s)</font>' % (spectra.shape)

   #Color iunit if referenced or not
   if not spectra.iunit:
      countstring = 'Iunit:&nbsp<font color="#197519">%s</font>' % spectra.full_iunit
   else: #orange
      countstring = 'Iunit:&nbsp<font color="#FF3300">%s</font>' % spectra.full_iunit

   ftunit = getattr(spectra, 'full_varunit', 'None')
   spunit = getattr(spectra, 'full_specunit', 'None')

   outline = "%s&nbsp%s%s [%s X %s] %s %s\n" % \
      (spectra.name, 
       colorshape,
       delim,
       ftunit,
       spunit,
       delim,
       countstring)        

   # Change output based on Spectra vs. Spectrum
   obj = spectra._frame
   if isinstance(obj, Series):
      obj = DataFrame(obj, columns=[spectra.specifier])

   # Call DataFrame _repr_html
   #outline += '<font color="#0000CD">This is some text!</font>'
   dfhtml = obj._repr_html_(*args, **kwargs)
   return ('<h4>%s</h4>' % ''.join(outline)) +'<br>'+ dfhtml
Example #4
0
 def test_to_html_border_option(self):
     df = DataFrame({'A': [1, 2]})
     with option_context('display.html.border', 0):
         result = df.to_html()
         assert 'border="0"' in result
         assert 'border="0"' in df._repr_html_()
Example #5
0
    def test_to_html_truncate_multi_index_sparse_off(self):
        pytest.skip("unreliable on travis")
        arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
                  ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
        df = DataFrame(index=arrays, columns=arrays)
        fmt.set_option('display.max_rows', 7)
        fmt.set_option('display.max_columns', 7)
        fmt.set_option('display.multi_sparse', False)
        result = df._repr_html_()
        expected = '''\
<div{0}>
<table border="1" class="dataframe">
  <thead>
    <tr>
      <th></th>
      <th></th>
      <th>bar</th>
      <th>bar</th>
      <th>baz</th>
      <th>...</th>
      <th>foo</th>
      <th>qux</th>
      <th>qux</th>
    </tr>
    <tr>
      <th></th>
      <th></th>
      <th>one</th>
      <th>two</th>
      <th>one</th>
      <th>...</th>
      <th>two</th>
      <th>one</th>
      <th>two</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>bar</th>
      <th>one</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>bar</th>
      <th>two</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>baz</th>
      <th>one</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>foo</th>
      <th>two</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>qux</th>
      <th>one</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>qux</th>
      <th>two</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
  </tbody>
</table>
<p>8 rows × 8 columns</p>
</div>'''.format(div_style)
        if compat.PY2:
            expected = expected.decode('utf-8')
        assert result == expected
Example #6
0
    def test_to_html_truncate(self):
        pytest.skip("unreliable on travis")
        index = pd.DatetimeIndex(start='20010101', freq='D', periods=20)
        df = DataFrame(index=index, columns=range(20))
        fmt.set_option('display.max_rows', 8)
        fmt.set_option('display.max_columns', 4)
        result = df._repr_html_()
        expected = '''\
<div{0}>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>...</th>
      <th>18</th>
      <th>19</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2001-01-01</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2001-01-02</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2001-01-03</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2001-01-04</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>2001-01-17</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2001-01-18</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2001-01-19</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2001-01-20</th>
      <td>NaN</td>
      <td>NaN</td>
      <td>...</td>
      <td>NaN</td>
      <td>NaN</td>
    </tr>
  </tbody>
</table>
<p>20 rows × 20 columns</p>
</div>'''.format(div_style)
        if compat.PY2:
            expected = expected.decode('utf-8')
        assert result == expected
Example #7
0
 def test_to_html_border_option(self):
     df = DataFrame({'A': [1, 2]})
     with pd.option_context('html.border', 0):
         result = df.to_html()
         self.assertTrue('border="0"' in result)
         self.assertTrue('border="0"' in df._repr_html_())