Skip to content

Instantly share code, notes, and snippets.

@taldcroft
Last active August 29, 2015 14:11
Show Gist options
  • Save taldcroft/6b8635ca8c85885e9f27 to your computer and use it in GitHub Desktop.
Save taldcroft/6b8635ca8c85885e9f27 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:125a815e8d0368e68b6b0d0adc12b5203312b94712ece9dd43b4ad436030faab"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"from astropy.table import *"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from astropy.table.table_helpers import *\n",
"import astropy.units as u"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"t = simple_table(3, cols=15)\n",
"t['a'].unit = u.m\n",
"t['dd'] = np.arange(2 * len(t)).reshape(-1, 2)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### HTML repr for IPython notebook (same as text console repr)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"t"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<Table masked=False length=3>\n",
"<table id=\"table4433428112\">\n",
"<thead><tr><th>a</th><th>b</th><th>c</th><th>d</th><th>e</th><th>f</th><th>g</th><th>h</th><th>i</th><th>j</th><th>k</th><th>l</th><th>m</th><th>n</th><th>o</th><th>dd [2]</th></tr></thead>\n",
"<thead><tr><th>m</th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th></tr></thead>\n",
"<thead><tr><th>int32</th><th>float32</th><th>string8</th><th>int32</th><th>float32</th><th>string8</th><th>int32</th><th>float32</th><th>string8</th><th>int32</th><th>float32</th><th>string8</th><th>int32</th><th>float32</th><th>string8</th><th>int64</th></tr></thead>\n",
"<tr><td>1</td><td>1.0</td><td>c</td><td>4</td><td>4.0</td><td>f</td><td>7</td><td>7.0</td><td>i</td><td>10</td><td>10.0</td><td>l</td><td>13</td><td>13.0</td><td>o</td><td>0 .. 1</td></tr>\n",
"<tr><td>2</td><td>2.0</td><td>d</td><td>5</td><td>5.0</td><td>g</td><td>8</td><td>8.0</td><td>j</td><td>11</td><td>11.0</td><td>m</td><td>14</td><td>14.0</td><td>p</td><td>2 .. 3</td></tr>\n",
"<tr><td>3</td><td>3.0</td><td>e</td><td>6</td><td>6.0</td><td>h</td><td>9</td><td>9.0</td><td>k</td><td>12</td><td>12.0</td><td>n</td><td>15</td><td>15.0</td><td>q</td><td>4 .. 5</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
"<Table masked=False length=3>\n",
" a b c d e ... l m n o dd [2]\n",
" m ... \n",
"int32 float32 string8 int32 float32 ... string8 int32 float32 string8 int64 \n",
"----- ------- ------- ----- ------- ... ------- ----- ------- ------- ------\n",
" 1 1.0 c 4 4.0 ... l 13 13.0 o 0 .. 1\n",
" 2 2.0 d 5 5.0 ... m 14 14.0 p 2 .. 3\n",
" 3 3.0 e 6 6.0 ... n 15 15.0 q 4 .. 5"
]
}
],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Console window repr"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(repr(t))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"<Table masked=False length=3>\n",
" a b c d e ... l m n o dd [2]\n",
" m ... \n",
"int32 float32 string8 int32 float32 ... string8 int32 float32 string8 int64 \n",
"----- ------- ------- ----- ------- ... ------- ----- ------- ------- ------\n",
" 1 1.0 c 4 4.0 ... l 13 13.0 o 0 .. 1\n",
" 2 2.0 d 5 5.0 ... m 14 14.0 p 2 .. 3\n",
" 3 3.0 e 6 6.0 ... n 15 15.0 q 4 .. 5\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### print output"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(t)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" a b c d e f g h i j k l m n o dd [2]\n",
" m \n",
"--- --- --- --- --- --- --- --- --- --- ---- --- --- ---- --- ------\n",
" 1 1.0 c 4 4.0 f 7 7.0 i 10 10.0 l 13 13.0 o 0 .. 1\n",
" 2 2.0 d 5 5.0 g 8 8.0 j 11 11.0 m 14 14.0 p 2 .. 3\n",
" 3 3.0 e 6 6.0 h 9 9.0 k 12 12.0 n 15 15.0 q 4 .. 5\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Column notebook repr is now formatted HTML"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"t['dd']"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"&lt;Column name=&apos;dd&apos; dtype=&apos;int64&apos; shape=(2,) length=3&gt;\n",
"<table>\n",
"<tr><td>0 .. 1</td></tr>\n",
"<tr><td>2 .. 3</td></tr>\n",
"<tr><td>4 .. 5</td></tr>\n",
"</table>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
"<Column name='dd' dtype='int64' shape=(2,) length=3>\n",
"0 .. 1\n",
"2 .. 3\n",
"4 .. 5"
]
}
],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Console repr is formatted and looks like notebook repr"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(repr(t['dd'])) # Console output"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"<Column name='dd' dtype='int64' shape=(2,) length=3>\n",
"0 .. 1\n",
"2 .. 3\n",
"4 .. 5\n"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### str and repr differ"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(t['dd'])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"dd [2]\n",
"------\n",
"0 .. 1\n",
"2 .. 3\n",
"4 .. 5\n"
]
}
],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"t.pprint(show_dtype=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" a b c d e ... l m n o dd [2]\n",
" m ... \n",
"int32 float32 string8 int32 float32 ... string8 int32 float32 string8 int64 \n",
"----- ------- ------- ----- ------- ... ------- ----- ------- ------- ------\n",
" 1 1.0 c 4 4.0 ... l 13 13.0 o 0 .. 1\n",
" 2 2.0 d 5 5.0 ... m 14 14.0 p 2 .. 3\n",
" 3 3.0 e 6 6.0 ... n 15 15.0 q 4 .. 5\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For long tables or columns that are clipped you get a \"Length = .. rows\" at the bottom with print()"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"t2 = simple_table(100)\n",
"print(t2)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" a b c \n",
"--- ----- ---\n",
" 1 1.0 c\n",
" 2 2.0 d\n",
" 3 3.0 e\n",
" 4 4.0 f\n",
" 5 5.0 g\n",
" 6 6.0 h\n",
" 7 7.0 i\n",
" 8 8.0 j\n",
" 9 9.0 k\n",
" 10 10.0 l\n",
" 11 11.0 m\n",
"... ... ...\n",
" 90 90.0 N\n",
" 91 91.0 O\n",
" 92 92.0 P\n",
" 93 93.0 Q\n",
" 94 94.0 R\n",
" 95 95.0 S\n",
" 96 96.0 T\n",
" 97 97.0 U\n",
" 98 98.0 V\n",
" 99 99.0 W\n",
"100 100.0 X\n",
"Length = 100 rows\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(t2['a'])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" a \n",
"---\n",
" 1\n",
" 2\n",
" 3\n",
" 4\n",
" 5\n",
" 6\n",
" 7\n",
" 8\n",
" 9\n",
" 10\n",
" 11\n",
"...\n",
" 91\n",
" 92\n",
" 93\n",
" 94\n",
" 95\n",
" 96\n",
" 97\n",
" 98\n",
" 99\n",
"100\n",
"Length = 100 rows\n"
]
}
],
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For repr there is no \"Length = NN rows\" because length is shown up top"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(repr(t2))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"<Table masked=False length=100>\n",
" a b c \n",
"int32 float32 string8\n",
"----- ------- -------\n",
" 1 1.0 c\n",
" 2 2.0 d\n",
" 3 3.0 e\n",
" 4 4.0 f\n",
" 5 5.0 g\n",
" 6 6.0 h\n",
" 7 7.0 i\n",
" 8 8.0 j\n",
" 9 9.0 k\n",
" 10 10.0 l\n",
" 11 11.0 m\n",
" ... ... ...\n",
" 91 91.0 O\n",
" 92 92.0 P\n",
" 93 93.0 Q\n",
" 94 94.0 R\n",
" 95 95.0 S\n",
" 96 96.0 T\n",
" 97 97.0 U\n",
" 98 98.0 V\n",
" 99 99.0 W\n",
" 100 100.0 X\n"
]
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment