Needs to coerce:
e.g.
In [1]: import pandas.util.testing as tm
In [2]: pan = tm.makePanel()
In [3]: pan
Out[3]:
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 30 (major_axis) x 4 (minor_axis)
Items axis: ItemA to ItemC
Major_axis axis: 2000-01-03 00:00:00 to 2000-02-11 00:00:00
Minor_axis axis: A to D
In [4]: pan.drop('2000-01-03', axis=1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-11e47d7c99f1> in <module>()
----> 1 pan.drop('2000-01-03', axis=1)
../pandas/core/generic.pyc in drop(self, labels, axis, level)
1112 new_axis = axis.drop(labels, level=level)
1113 else:
-> 1114 new_axis = axis.drop(labels)
1115 dropped = self.reindex(**{ axis_name: new_axis })
1116 try:
../pandas/core/index.pyc in drop(self, labels)
1614 mask = indexer == -1
1615 if mask.any():
-> 1616 raise ValueError('labels %s not contained in axis' % labels[mask])
1617 return self.delete(indexer)
1618
ValueError: labels ['2000-01-03'] not contained in axis
Comment From: jreback
related #6599
Comment From: jorisvandenbossche
Updated example with frame:
In [59]: df = tm.makeTimeDataFrame()
In [60]: df
Out[60]:
A B C D
2000-01-03 -0.394676 0.026933 1.435611 0.735617
2000-01-04 -2.095283 -0.623525 1.017788 -2.014091
2000-01-05 -0.770375 0.643865 -0.070327 -2.305731
2000-01-06 -1.188628 0.475190 -0.926808 -0.285167
2000-01-07 -0.125856 1.719509 0.184650 0.640200
...
In [62]: df.drop('2000-01-03', axis=0)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-62-0844c2a2456f> in <module>()
----> 1 df.drop('2000-01-03', axis=0)
/home/joris/scipy/pandas/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
2515 for axis, labels in axes.items():
2516 if labels is not None:
-> 2517 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
2518
2519 if inplace:
/home/joris/scipy/pandas/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors)
2547 new_axis = axis.drop(labels, level=level, errors=errors)
2548 else:
-> 2549 new_axis = axis.drop(labels, errors=errors)
2550 dropped = self.reindex(**{axis_name: new_axis})
2551 try:
/home/joris/scipy/pandas/pandas/core/indexes/base.py in drop(self, labels, errors)
3757 if errors != 'ignore':
3758 raise ValueError('labels %s not contained in axis' %
-> 3759 labels[mask])
3760 indexer = indexer[~mask]
3761 return self.delete(indexer)
ValueError: labels ['2000-01-03'] not contained in axis
In [63]: df.drop(pd.Timestamp('2000-01-03'), axis=0)
Out[63]:
A B C D
2000-01-04 -3.354600 -0.610585 -0.503516 -1.058210
2000-01-05 2.253061 0.083150 0.236107 -1.475713
2000-01-06 -0.299333 0.957344 2.024540 -0.424540
2000-01-07 0.396877 -1.124760 -0.249968 -1.139085
...
Comment From: jreback
@jorisvandenbossche why do you think this should work? this is partial string indexing. I mean it could, but I think drop being strict is a good thing.
Comment From: jorisvandenbossche
I am not necessarily saying that this should work. I was going through old issues and closing/updating some, so updated the title / added a better example of the original issue here.
I agree partial strings interpretation should not work with drop, but in the example above, it is not a partial string that embodies multiple rows. It is just a single label represented by a string instead of Timestamp
object. So supporting that is I think a bit less controversial.
Comment From: mroeschke
Looks to work on main now. Could use a test
Comment From: PrimeF
@MarcoGorelli Can this issue be closed given that it is both fixed and tested by now?
Comment From: MarcoGorelli
thanks, not sure why it didn't close automatically