Skip to content

REGR: slicing an irregular DatetimeIndex with NaT fails with AssertionError #36953

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
jorisvandenbossche opened this issue Oct 7, 2020 · 9 comments · Fixed by #37023
Closed
Labels
Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Oct 7, 2020

This seems to be triggered in a very specific case, i.e. an irregular time series and a missing value as last element in the index:

increment = pd.Series(pd.to_timedelta([30.0, 30.1, 29.9, 30.0], unit='s')).cumsum()
increment[-1] = None
index = pd.Timestamp("2012-01-01 09:00") + increment
df = pd.Series(range(len(index)), index=index).to_frame()

In [11]: df["2012-01-01":"2012-01-05"]
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-11-ded270432cfc> in <module>
----> 1 df["2012-01-01":"2012-01-05"]

~/miniconda3/envs/pandas11/lib/python3.8/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2883             # either we have a slice or we have a string that can be converted
   2884             #  to a slice for partial-string date indexing
-> 2885             return self._slice(indexer, axis=0)
   2886 
   2887         # Do we have a (boolean) DataFrame?

~/miniconda3/envs/pandas11/lib/python3.8/site-packages/pandas/core/generic.py in _slice(self, slobj, axis)
   3552         Slicing with this method is *always* positional.
   3553         """
-> 3554         assert isinstance(slobj, slice), type(slobj)
   3555         axis = self._get_block_manager_axis(axis)
   3556         result = self._constructor(self._mgr.get_slice(slobj, axis=axis))

AssertionError: <class 'numpy.ndarray'>
@jorisvandenbossche jorisvandenbossche added Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version labels Oct 7, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1.4 milestone Oct 7, 2020
@CloseChoice
Copy link
Member

Do you know in which version this still worked?

@jorisvandenbossche
Copy link
Member Author

In 1.0.x it still works, so regression in 1.1.x

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Oct 9, 2020
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Oct 9, 2020
@simonjayhawkins
Copy link
Member

first bad commit: [4ac1e5f] CLN: assorted cleanups (#31938) where the assertion was added cc @jbrockmendel

@simonjayhawkins
Copy link
Member

duplicate of #35509 so closing

@simonjayhawkins simonjayhawkins added Duplicate Report Duplicate issue or pull request and removed Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version Datetime Datetime data dtype labels Oct 9, 2020
@simonjayhawkins simonjayhawkins removed this from the 1.1.4 milestone Oct 9, 2020
@jorisvandenbossche
Copy link
Member Author

jorisvandenbossche commented Oct 9, 2020

It might be the same underlying cause, it's a different use case, so reopening to ensure we also test this when fixing the bug.

@jorisvandenbossche jorisvandenbossche added Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version Datetime Datetime data dtype and removed Duplicate Report Duplicate issue or pull request labels Oct 9, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1.4 milestone Oct 9, 2020
@simonjayhawkins
Copy link
Member

@jorisvandenbossche in that case, probably need to make the code sample more minimal and reproducible, i.e. remove the randomness or seed.

@simonjayhawkins simonjayhawkins added the Needs Info Clarification about behavior needed to assess issue label Oct 9, 2020
@jorisvandenbossche
Copy link
Member Author

But @simonjayhawkins thanks a lot for finding the cause! (seems just the assert that was added that we might be able to remove)

@jorisvandenbossche
Copy link
Member Author

jorisvandenbossche commented Oct 9, 2020

The randomness doesn't matter really; I think I quite clearly described the case when this occurs: irregular (no freq) and NaT as last element?

@jorisvandenbossche jorisvandenbossche removed the Needs Info Clarification about behavior needed to assess issue label Oct 9, 2020
@jorisvandenbossche
Copy link
Member Author

Updated the top post with some fixed numbers instead of the np.random.randn()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants