Skip to content

Commit cf62037

Browse files
JonasAbernotjreback
authored andcommitted
fix issue #9680
1 parent c98dbc7 commit cf62037

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
@@ -211,11 +211,7 @@ Bug Fixes
211211

212212

213213

214-
215-
216-
217-
218-
214+
- Bug in invalid attribute access on a ``TimedeltaIndex`` incorrectly raised ``ValueError`` instead of ``AttributeError`` (:issue:`9680`)
219215

220216

221217

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)