Skip to content

Commit b983243

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 4cd8458 commit b983243

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
@@ -35,7 +35,8 @@ Other Enhancements
3535
Backwards incompatible API changes
3636
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3737

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

4041
.. _whatsnew_0210.api:
4142

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)