Skip to content

Commit

Permalink
API: link_df_iter() checks for DataFrame by duck typing
Browse files Browse the repository at this point in the history
  • Loading branch information
nkeim committed Mar 5, 2015
1 parent 953083d commit 324fdf3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions trackpy/linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,9 @@ def link_df_iter(features, search_range, memory=0,

# Non-destructively check the type of the first item of features
feature_iter, feature_checktype_iter = itertools.tee(iter(features))
if not isinstance(next(itertools.islice(feature_checktype_iter, 1)),
pd.DataFrame):
try: # If it quacks like a DataFrame...
next(itertools.islice(feature_checktype_iter, 1)).reset_index()
except AttributeError:
raise ValueError("Features data must be an iterable of DataFrames, one per "
"video frame. Use link_df() if you have a single DataFrame "
"describing multiple frames.")
Expand Down

0 comments on commit 324fdf3

Please sign in to comment.