Skip to content

Commit e0bbaff

Browse files
committed
API: Raise AttributeError on closed HDFStore
Previously, we called _check_if_open, which would raise a ClosedFileError whenever the desired attribute wasn't found. This prevented the check required for PEP519 to work properly, since hasattr shouldn't raise that error.
1 parent 539de79 commit e0bbaff

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

doc/source/whatsnew/v0.21.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Backwards incompatible API changes
4040
- Support has been dropped for Python 3.4 (:issue:`15251`)
4141
- The Categorical constructor no longer accepts a scalar for the ``categories`` keyword. (:issue:`16022`)
4242

43+
- Accessing a non-existent attribute on a closed :class:`HDFStore` will now
44+
raise an ``AttributeError`` rather than a ``ClosedFileError`` (:issue:`16301`)
4345

4446
.. _whatsnew_0210.api:
4547

pandas/io/pytables.py

-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ def __delitem__(self, key):
472472

473473
def __getattr__(self, name):
474474
""" allow attribute access to get stores """
475-
self._check_if_open()
476475
try:
477476
return self.get(name)
478477
except:

pandas/tests/io/test_pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4453,7 +4453,7 @@ def f():
44534453
pytest.raises(ClosedFileError, lambda: 'df' in store)
44544454
pytest.raises(ClosedFileError, lambda: len(store))
44554455
pytest.raises(ClosedFileError, lambda: store['df'])
4456-
pytest.raises(ClosedFileError, lambda: store.df)
4456+
pytest.raises(AttributeError, lambda: store.df)
44574457
pytest.raises(ClosedFileError, store.select, 'df')
44584458
pytest.raises(ClosedFileError, store.get, 'df')
44594459
pytest.raises(ClosedFileError, store.append, 'df2', df)

0 commit comments

Comments
 (0)