Skip to content

Commit 8c10784

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 53e1d39 commit 8c10784

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

doc/source/whatsnew/v0.21.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Other Enhancements
3636
Backwards incompatible API changes
3737
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3838

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

4142
.. _whatsnew_0210.api:
4243

pandas/io/pytables.py

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

467467
def __getattr__(self, name):
468468
""" allow attribute access to get stores """
469-
self._check_if_open()
470469
try:
471470
return self.get(name)
472471
except:

pandas/tests/io/test_pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4377,7 +4377,7 @@ def f():
43774377
pytest.raises(ClosedFileError, lambda: 'df' in store)
43784378
pytest.raises(ClosedFileError, lambda: len(store))
43794379
pytest.raises(ClosedFileError, lambda: store['df'])
4380-
pytest.raises(ClosedFileError, lambda: store.df)
4380+
pytest.raises(AttributeError, lambda: store.df)
43814381
pytest.raises(ClosedFileError, store.select, 'df')
43824382
pytest.raises(ClosedFileError, store.get, 'df')
43834383
pytest.raises(ClosedFileError, store.append, 'df2', df)

0 commit comments

Comments
 (0)