Skip to content

Commit

Permalink
Better way of pulling out metadata from pandas DataFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
kboone committed Apr 23, 2019
1 parent ea6c357 commit d93981e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions avocado/astronomical_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AstronomicalObject():
Parameters
----------
metadata : dict or pandas Series
metadata : dict-like
Metadata for this object. This is represented using a dict
internally, and must be able to be cast to a dict. Any keys and
information are allowed. Various functions assume that the
Expand All @@ -36,7 +36,7 @@ class AstronomicalObject():
"""
def __init__(self, metadata, observations):
"""Create a new AstronomicalObject"""
self.metadata = metadata
self.metadata = dict(metadata)
self.observations = observations

@property
Expand Down
4 changes: 3 additions & 1 deletion avocado/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def __init__(self, name, metadata, observations=None):

# Load each astronomical object in the dataset.
objects = []
meta_dicts = self.metadata.to_dict('records')
for object_id, object_observations in \
observations.groupby('object_id'):
object_metadata = metadata.loc[object_id]
meta_index = self.metadata.index.get_loc(object_id)
object_metadata = meta_dicts[meta_index]
new_object = AstronomicalObject(object_metadata,
object_observations)
objects.append(new_object)
Expand Down

0 comments on commit d93981e

Please sign in to comment.