Skip to content
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

BUG: rename axes #51

Merged
merged 1 commit into from
Jul 18, 2018
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
17 changes: 13 additions & 4 deletions bayesalpha/author_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ def rebuild_model(self, data=None):
data = (self.trace
._data
.to_pandas()
.rename('perf_sharpe_ratio_is')
.reset_index()
# Rename back to the expected column names.
.rename_axis(['meta_user_id',
'meta_algorithm_id',
'meta_code_id',
'perf_sharpe_ratio_is'], axis=1)
.copy())

return AuthorModelBuilder(data)
Expand Down Expand Up @@ -240,9 +244,14 @@ def fit_authors(data,
trace.attrs['model-type'] = AUTHOR_MODEL_TYPE

if save_data:
d = data.set_index(['meta_user_id',
'meta_algorithm_id',
'meta_code_id']).squeeze()
d = (data.set_index(['meta_user_id',
'meta_algorithm_id',
'meta_code_id'])
# Rename index names to avoid name collision.
.rename_axis(['data_meta_user_id',
'data_meta_algorithm_id',
'data_meta_code_id'], axis=0)
.squeeze())
Copy link
Collaborator

@aseyboldt aseyboldt Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the squeeze do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It coerces the DataFrame (with one column) into a pd.Series so that xarray turns it into a DataArray instead of a DataSet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

trace['_data'] = xr.DataArray(d)

return AuthorModelResult(trace)
Expand Down