Skip to content

BUG: Trajectories() objects don't get saved transparently in a HDFStore, raises TypeError #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
glyg opened this issue Mar 31, 2014 · 3 comments

Comments

@glyg
Copy link
Member

glyg commented Mar 31, 2014

With trajs being a Trajectories object, this fails:

import pandas as pd
with pd.get_store('with_gaps.h5') as store:
    store['trajs'] = trajs

raises:

TypeError: cannot properly create the storer for:
 [_TYPE_MAP] [group->/trajs (Group) '',
value-><class'sktracker.trajectories.trajectories.Trajectories'>,
format->fixed,
append->False,kwargs->{'encoding': None}]

I think it's a bug, because users will assume they can do that. Of course, the following works smoothly:

import pandas as pd
with pd.get_store('with_gaps.h5') as store:
    store['trajs'] = pd.DataFrame(trajs)

I'll post something in pandas to see if there's a way around that on their side (after all, sub classing should be supported). I'm not sure what to do on our side... Of course, objectsio should take care of that, but I'd feel better if that kind of TypeError won't appear at all

@glyg glyg added Bug labels Mar 31, 2014
@glyg glyg self-assigned this Mar 31, 2014
@glyg
Copy link
Member Author

glyg commented Mar 31, 2014

@glyg
Copy link
Member Author

glyg commented Mar 31, 2014

Much more related:
pandas-dev/pandas#4271

On the thread, you can find this:

import pandas as pd
from pandas.io import pytables 

class MyPanel(pd.Panel):
    pass

class MyPanelStorer(pytables.PanelStorer):
    pandas_kind = 'mywide'
    obj_type = MyPanel
pytables._TYPE_MAP[MyPanel] = 'mywide'
pytables._STORER_MAP['mywide'] = 'MyPanelStorer'
pytables.MyPanelStorer = MyPanelStorer 

Turns out this is outdated a bit, but I think the best solution is to add that:

pytables._TYPE_MAP[Trajectories] = 'frame'

Which basically writes trajectories as DataFrames. The simpler the better I guess

@glyg glyg closed this as completed in 987e282 Mar 31, 2014
@hadim
Copy link
Contributor

hadim commented Mar 31, 2014

I agree that we should support that. People should be able to run tracking and save results with Trajectories without using ObjectsIO at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants