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: added fix for column index for DatetimeIndex type #60528

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lukenalewajk
Copy link

Added fix in pandas/core/generic.py by adding the lines below to the take() method within core/generic.py, which is called in the getitem method in core/frame.py in order to the columns as objects.

        if axis == 1 and indices.ndim == 1 and is_range_indexer(indices, len(self.columns)):
            # check if index is of type period, sets to object for slicing correct columns
            if isinstance(self.index, DatetimeIndex) or isinstance(self.index, PeriodIndex): 
                return self.copy(deep=False).astype('object')
            return self.copy(deep=False)

The method was not properly returning the right columns if the datatype was a DatetimeIndex or PeriodIndex. Added tests in pandas/tests/series/indexing/test_getitem.py to reflect these changes.

@lukenalewajk lukenalewajk changed the title added fix for column index for DatetimeIndex type BUG: added fix for column index for DatetimeIndex type Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: period[h] + column splicing is not work
2 participants