Skip to content

Rolling on DataFrameGroupBy duplicated index column when part of the grouping cols is from index #36816

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
wants to merge 1 commit into from

Conversation

phofl
Copy link
Member

@phofl phofl commented Oct 2, 2020

…grouping cols is from index

Could not find a elegant way, to avoid adding the components in the for loop, so I dropped it from the resulting MultiIndex again.

Had to change a test, which depended on the wrong behavior.

cc @mroeschke

@jreback jreback added Groupby Window rolling, ewma, expanding labels Oct 2, 2020
@jreback jreback added this to the 1.2 milestone Oct 2, 2020
@jreback jreback added the Bug label Oct 2, 2020
@@ -2209,6 +2209,20 @@ def _apply(
grouped_index_name = [*grouped_object_index.names]
groupby_keys = [grouping.name for grouping in self._groupby.grouper._groupings]
result_index_names = groupby_keys + grouped_index_name
drop_levels = []
obj = self._groupby._selected_obj
Copy link
Contributor

Choose a reason for hiding this comment

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

this is way to special cases; we need to figure out why this is happening and adjust the logic more generally.

Copy link
Member Author

@phofl phofl Oct 2, 2020

Choose a reason for hiding this comment

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

This is happening because of

        for key, values in self._groupby.grouper.indices.items():
            for value in values:
                data = [
                    *com.maybe_make_list(key),
                    *com.maybe_make_list(grouped_object_index[value]),
                ]
                result_index_data.append(tuple(data))

        result_index = MultiIndex.from_tuples(
            result_index_data, names=result_index_names
        )

which is a few lines below. self._groupby.grouper.indices.items()represents the grouping columns and grouped_object_index[value] the index used for the rolling operation. If parts of the grouping columns are from the index, we duplicate these here. As I wrote, I could not figure out a simple way to avoid this within the loop.

@jreback jreback removed this from the 1.2 milestone Oct 2, 2020
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

As explained in #36794 (comment), I don't view this as a bug that needs fixing

@phofl phofl closed this Oct 2, 2020
@phofl phofl deleted the 36794 branch October 3, 2020 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Series.groupby.rolling duplicates index when grouping over index
3 participants