-
Notifications
You must be signed in to change notification settings - Fork 0
/
galyleo_table.html
263 lines (245 loc) · 22.5 KB
/
galyleo_table.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module galyleo_table</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>galyleo_table</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/Users/rick/Projects/engageLively/el-galyleo-client/galyleo/galyleo_table.py">/Users/rick/Projects/engageLively/el-galyleo-client/galyleo/galyleo_table.py</a></font></td></tr></table>
<p><tt># BSD 3-Clause License</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="gviz_api.html">gviz_api</a><br>
</td><td width="25%" valign=top><a href="numpy.html">numpy</a><br>
</td><td width="25%" valign=top><a href="pandas.html">pandas</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="galyleo_table.html#GalyleoTable">GalyleoTable</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="GalyleoTable">class <strong>GalyleoTable</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt><a href="#GalyleoTable">GalyleoTable</a>(name: str)<br>
<br>
A Galyleo Dashboard Table. Used to create a Galyleo Dashboard Table from any of a number of sources, and then generate an <a href="builtins.html#object">object</a> that is suitable<br>
for storage (as a JSON file). A <a href="#GalyleoTable">GalyleoTable</a> is very similar to a Google Visualization data table, and can be<br>
converted to a Google Visualization Data Table on either the Python or the JavaScript side.<br>
Convenience routines provided here to import data from pandas, and json format.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="GalyleoTable-__init__"><strong>__init__</strong></a>(self, name: str)</dt><dd><tt>The DashboardTable Class. Sets the schema and data to be empty, and the name to be name<br>
<br>
Args:<br>
name (str): The nameo of the table</tt></dd></dl>
<dl><dt><a name="GalyleoTable-aggregate_by"><strong>aggregate_by</strong></a>(self, aggregate_column_names, new_column_name='count', new_table_name=None)</dt><dd><tt>Create a new table by aggregating over multiple columns. The resulting table<br>
contains the aggregate column names and the new column name, and for each<br>
unique combination of values among the aggregate column names, the count of rows in this<br>
table with that unique combination of values.<br>
The new table will have name new_table_name<br>
Throws an InvalidDataException if aggregate_column_names is not a subset of the names in self.<strong>schema</strong><br>
<br>
Args:<br>
aggregate_column_names: names of the columns to aggregate over<br>
new_column_name: name of the column for the aggregate count. Defaults to count<br>
new_table_name: name of the new table. If omitted, defaults to None, in which case a name will be generated<br>
<br>
Returns:<br>
A new table with name new_table_name, or a generated name if new_table_name == None<br>
<br>
Throws:<br>
InvalidDataException if one of the column names is missing</tt></dd></dl>
<dl><dt><a name="GalyleoTable-as_dictionary"><strong>as_dictionary</strong></a>(self)</dt><dd><tt>Return the form of the table as a dictionary. This is a dictionary<br>
of the form:<br>
{"name": <table_name>,"table": <table_struct>} <br>
where table_struct is of the form:<br>
{"columns": [<list of schema records],"rows": [<list of rows of the table>]}<br>
<br>
A schema record is a record of the form:<br>
{"name": < column_name>, "type": <column_type}, where type is one of the <br>
Galyleo types (GALYLEO_STRING, GALYLEO_NUMBER, GALYLEO_BOOLEAN,<br>
GALYLEO_DATE, GALYLEO_DATETIME, GALYLEO_TIME_OF_DAY). All of these are defined<br>
in galyleo_constants.<br>
<br>
Args:<br>
None<br>
<br>
Returns:<br>
{"name": <table_name>, "table": {"columns": <list of schema records], "rows": [<list of rows of the table>]}}</tt></dd></dl>
<dl><dt><a name="GalyleoTable-equal"><strong>equal</strong></a>(self, table, names_must_match=False)</dt><dd><tt>Test to see if this table is equal to another table, passed as<br>
an argument. Two tables are equal if their schemas are the same<br>
length and column names and types match, and if the data is the same,<br>
and in the same order. If names_must_match == True (default is False),<br>
then the names must also match<br>
<br>
Args:<br>
table (<a href="#GalyleoTable">GalyleoTable</a>): table to be checked for equality<br>
names_must_match (bool): (default False) if True, table names must also match<br>
<br>
Returns:<br>
True if equal, False otherwise</tt></dd></dl>
<dl><dt><a name="GalyleoTable-filter_by_function"><strong>filter_by_function</strong></a>(self, column_name, function, new_table_name, column_types={})</dt><dd><tt>Create a new table, with name table_name, with rows such that <br>
function(row[column_name]) == True. The new table will have<br>
columns {self.<strong>columns</strong>} - {column_name}, same types, and same order<br>
Throws an InvalidDataException if:<br>
1. new_table_name is None or not a string<br>
2. column_name is not a name of an existing column<br>
3. if column_types is not empty, the type of the selected column doesn't match one of the allowed types<br>
<br>
Args:<br>
column_name: the column to filter by<br>
function: a Boolean function with a single argument of the type of columns[column_name]<br>
new_table_name: name of the new table<br>
column_types: set of the allowed column types; if empty, any type is permitted<br>
<br>
Returns:<br>
A table with column[column_name] missing and filtered<br>
<br>
Throws:<br>
InvalidDataException if new_table_name is empty, column_name is not a name of an existing column, or the type of column_name isn't in column_types (if column_types is non-empty)</tt></dd></dl>
<dl><dt><a name="GalyleoTable-filter_equal"><strong>filter_equal</strong></a>(self, column_name, value, new_table_name, column_types)</dt><dd><tt>A convenience method over filter_by_function. This is identical to<br>
<a href="#GalyleoTable-filter_by_function">filter_by_function</a>(column_name, lambda x: x == value, new_table_name, column_types)<br>
<br>
Args:<br>
column_name: the column to filter by<br>
value: the value to march for equality<br>
new_table_name: name of the new table<br>
column_types: set of the allowed column types; if empty, any type is permitted<br>
<br>
Returns:<br>
A table with column[column_name] missing and filtered<br>
<br>
Throws:<br>
InvalidDataException if new_table_name is empty, column_name is not a name of an existing column, or the type of column_name isn't in column_types (if column_types is non-empty)</tt></dd></dl>
<dl><dt><a name="GalyleoTable-filter_range"><strong>filter_range</strong></a>(self, column_name, range_as_tuple, new_table_name, column_types)</dt><dd><tt>A convenience method over filter_by_function. This is identical to<br>
<a href="#GalyleoTable-filter_by_function">filter_by_function</a>(column_name, lambda x: x >= range_as_tuple[0], x <= range_as_tuple[1], new_table_name, column_types)<br>
<br>
Args:<br>
column_name: the column to filter by<br>
range_as_tupe: the tuple representing the range<br>
new_table_name: name of the new table<br>
column_types: set of the allowed column types; if empty, any type is permitted<br>
<br>
Returns:<br>
A table with column[column_name] missing and filtered<br>
<br>
Throws:<br>
InvalidDataException if new_table_name is empty, column_name is not a name of an existing column, or the type of column_name isn't in column_types (if column_types is non-empty), if len(range_as_tuple) != 2</tt></dd></dl>
<dl><dt><a name="GalyleoTable-from_json"><strong>from_json</strong></a>(self, json_form, overwrite_name=True)</dt><dd><tt>Load the table from a JSON string, of the form produced by toJSON(). Note<br>
that if the overwrite_name parameter = True (the default), this will also<br>
overwrite the table name.<br>
<br>
Throws InvalidDataException id json_form is malformed<br>
<br>
Args:<br>
json_form: A JSON form of the Dictionary<br>
<br>
Returns:<br>
None<br>
<br>
Throws:<br>
InvalidDataException if json_form is malformed</tt></dd></dl>
<dl><dt><a name="GalyleoTable-load_from_dataframe"><strong>load_from_dataframe</strong></a>(self, dataframe, schema=None)</dt><dd><tt>Load from a Pandas Dataframe. The schema is given in the optional second parameter,<br>
as a list of records {"name": <name>, "type": <type>}, where type is a Galyleo type. (GALYLEO_STRING, GALYLEO_NUMBER, GALYLEO_BOOLEAN,<br>
GALYLEO_DATE, GALYLEO_DATETIME, GALYLEO_TIME_OF_DAY). <br>
If the second parameter is not present, the schema is derived from the name and<br>
column types of the dataframe, and each row of the dataframe becomes a row<br>
of the table. <br>
<br>
Args:<br>
<br>
dataframe (pandas dataframe): the pandas dataframe to load from<br>
schema (list of dictionaries): if present, the schema in list of dictionary form; each dictionary is of the form {"name": <column name>, "type": <column type>}</tt></dd></dl>
<dl><dt><a name="GalyleoTable-load_from_dictionary"><strong>load_from_dictionary</strong></a>(self, dict)</dt><dd><tt>load data from a dictionary of the form: {"columns": [<list of schema records], "rows": [<list of rows of the table>]}<br>
<br>
A schema record is a record of the form:<br>
{"name": < column_name>, "type": <column_type}, where type is one of the <br>
Galyleo types (GALYLEO_STRING, GALYLEO_NUMBER, GALYLEO_BOOLEAN,<br>
GALYLEO_DATE, GALYLEO_DATETIME, GALYLEO_TIME_OF_DAY). <br>
<br>
Throws InvalidDataException if the dictionary is of the wrong format<br>
or the rows don't match the columns.<br>
<br>
Args:<br>
dict: the table as a dictionary (a value returned by as_dictionary)<br>
<br>
Throws:<br>
InvalidDataException if dict is malformed</tt></dd></dl>
<dl><dt><a name="GalyleoTable-load_from_schema_and_data"><strong>load_from_schema_and_data</strong></a>(self, schema: list, data: list)</dt><dd><tt>Load from a pair (schema, data).<br>
Schema is a list of pairs [(<column_name>, <column_type>)]<br>
where column_type is one of the Galyleo types (GALYLEO_STRING, GALYLEO_NUMBER, GALYLEO_BOOLEAN,<br>
GALYLEO_DATE, GALYLEO_DATETIME, GALYLEO_TIME_OF_DAY). All of these are defined<br>
in galyleo_constants. data is a list of lists, where each list is a row of <br>
the table. Two conditions:<br>
<br>
(1) Each type must be one of types listed above<br>
<br>
(2) Each list in data must have the same length as the schema, and the type of each<br>
element must match the corresponding schema type<br>
<br>
throws an InvalidDataException if either of these are violated<br>
<br>
Args:<br>
schema (list of pairs, (name, type)): the schema as a list of pairs<br>
data (list of lists): the data as a list of lists</tt></dd></dl>
<dl><dt><a name="GalyleoTable-pivot_on_column"><strong>pivot_on_column</strong></a>(self, pivot_column_name, value_column_name, new_table_name, pivot_column_values={}, other_column=False)</dt><dd><tt>The pivot_on_column method breaks out value_column into n separate columns, one for each<br>
member of pivot_column_values plus (if other_column = True), an "Other" column. This is easiest to see with an example. Consider a table with columns (Year, State, Party, Percentage). <a href="#GalyleoTable-pivot_on_column">pivot_on_column</a>('Party', {'Republican', 'Democratic'}, 'Percentage', 'pivot_table', False) would create a new table with columns Year, State, Republican, Democratic, where the values in the Republican and Democratic columns are the values in the Percentage column where the Party column value was Republican or Democratic, respectively. If Other = True, an additional column, Other, is found where the value is (generally) the sum of values where Party not equal Republican or Democratic<br>
<br>
Args:<br>
pivot_column_name: the column holding the keys to pivot on<br>
value_column_name: the column holding the values to spread out over the pivots<br>
new_table_name: name of the new table<br>
pivot_column_values: the values to pivot on. If empty, all values used<br>
other_column: if True, aggregate other values into a column<br>
<br>
Returns:<br>
A table as described in the comments above<br>
<br>
Throws:<br>
InvalidDataException if new_table_name is empty, pivot_column_name is not a name of an existing column, or value_column_name is not the name of an existing column</tt></dd></dl>
<dl><dt><a name="GalyleoTable-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>Return the table as a JSON string, suitable for transmitting as a message<br>
or saving to a file. This is just a JSON form of the dictionary form of<br>
the string. (See as_dictionary)<br>
<br>
Returns:<br>
<a href="#GalyleoTable-as_dictionary">as_dictionary</a>() as a JSON string</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>GALYLEO_BOOLEAN</strong> = 'boolean'<br>
<strong>GALYLEO_DATE</strong> = 'date'<br>
<strong>GALYLEO_DATETIME</strong> = 'datetime'<br>
<strong>GALYLEO_NUMBER</strong> = 'number'<br>
<strong>GALYLEO_SCHEMA_TYPES</strong> = ['string', 'number', 'boolean', 'date', 'datetime', 'timeofday']<br>
<strong>GALYLEO_STRING</strong> = 'string'<br>
<strong>GALYLEO_TIME_OF_DAY</strong> = 'timeofday'</td></tr></table>
</body></html>