Skip to content

Commit 261f2b4

Browse files
committed
fix issue pandas-dev#9680
1 parent ea1c501 commit 261f2b4

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

doc/source/whatsnew/v0.16.1.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ Bug Fixes
7070

7171
- Bug in ``transform`` causing length mismatch when null entries were present and a fast aggregator was being used (:issue:`9697`)
7272

73-
74-
75-
76-
77-
73+
- Bug : Trying to access absent attributes in TimedeltaIndex use to raise ValueError instead of AttributeError(:issue:`9680`)
7874

7975

8076
- Bug in ``Series.quantile`` on empty Series of type ``Datetime`` or ``Timedelta`` (:issue:`9675`)

pandas/tseries/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __contains__(self, key):
6767
try:
6868
res = self.get_loc(key)
6969
return np.isscalar(res) or type(res) == slice or np.any(res)
70-
except (KeyError, TypeError):
70+
except (KeyError, TypeError, ValueError):
7171
return False
7272

7373
@property

pandas/tseries/tests/test_base.py

+7
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,13 @@ def test_nonunique_contains(self):
745745
['00:01:00', '00:01:00', '00:00:01'])):
746746
tm.assertIn(idx[0], idx)
747747

748+
def test_unknown_attribute(self):
749+
#GH 9680
750+
tdi = pd.timedelta_range(start=0,periods=10,freq='1s')
751+
ts = pd.Series(np.random.normal(size=10),index=tdi)
752+
self.assertNotIn('foo',ts.__dict__.keys())
753+
self.assertRaises(AttributeError,lambda : ts.foo)
754+
748755

749756
class TestPeriodIndexOps(Ops):
750757

0 commit comments

Comments
 (0)