Skip to content

Commit

Permalink
Merge branch 'issue529'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Verweij committed Apr 14, 2019
2 parents f68b726 + 1f32d5f commit 9aadcca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 8 additions & 7 deletions trackpy/framewise_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ def __init__(self, filename, key='FrameData', mode='a', t_column='frame',
self._t_column = t_column
self.store = pd.HDFStore(self.filename, mode, **kwargs)

with pd.get_store(self.filename) as store:
try:
store[self.key]
except KeyError:
pass
else:
self._validate_node(use_tabular_copy)
store = pd.HDFStore(self.filename)
try:
store[self.key]
except KeyError:
pass
else:
self._validate_node(use_tabular_copy)
store.close()

@property
def t_column(self):
Expand Down
12 changes: 11 additions & 1 deletion trackpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,17 @@ def _pandas_sort_pre_017(df, by, *args, **kwargs):
return df.sort(*args, columns=by, **kwargs)

def _pandas_sort_post_017(df, by, *args, **kwargs):
"""Use sort_values() to sort a DataFrame"""
"""
Use sort_values() to sort a DataFrame
This raises a ValueError if the given value is both
a column and an index label, i.e.:
ValueError: 'frame' is both an index level and a column
label, which is ambiguous.
Because we usually sort by columns, we can rename
the index to supress the ValueError.
"""
if df.index.name is not None and df.index.name in by:
df.index.name += '_index'
return df.sort_values(*args, by=by, **kwargs)

if is_pandas_since_017:
Expand Down

0 comments on commit 9aadcca

Please sign in to comment.