Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ def from_rows(cls, rows, labels):

@classmethod
def from_records(cls, records):
"""Create a table from a sequence of records (dicts with fixed keys)."""
"""Create a table from a sequence of records (dicts with fixed keys).

Args:

records: A list of dictionaries with same keys.

Returns:

If the list is empty, it will return an empty table.
Otherwise, it will return a table with the dictionary's keys as the column name, and the corresponding data.
If the dictionaries do not have identical keys, the keys of the first dictionary in the list is used.

"""
if not records:
return cls()
labels = sorted(list(records[0].keys()))
Expand Down Expand Up @@ -158,7 +170,16 @@ def from_df(cls, df, keep_index=False):

@classmethod
def from_array(cls, arr):
"""Convert a structured NumPy array into a Table."""
"""Convert a structured NumPy array into a Table.

Args:

arr: A structured numpy array

Returns:

A table with the field names as the column names and the corresponding data.
"""
return cls().with_columns([(f, arr[f]) for f in arr.dtype.names])

#################
Expand Down