2
2
High level interface to PyTables for reading and writing pandas data structures
3
3
to disk
4
4
"""
5
+ from contextlib import suppress
5
6
import copy
6
7
from datetime import date , tzinfo
7
8
import itertools
@@ -202,12 +203,10 @@ def _tables():
202
203
# set the file open policy
203
204
# return the file open policy; this changes as of pytables 3.1
204
205
# depending on the HDF5 version
205
- try :
206
+ with suppress ( AttributeError ) :
206
207
_table_file_open_policy_is_strict = (
207
208
tables .file ._FILE_OPEN_POLICY == "strict"
208
209
)
209
- except AttributeError :
210
- pass
211
210
212
211
return _table_mod
213
212
@@ -423,10 +422,8 @@ def read_hdf(
423
422
except (ValueError , TypeError , KeyError ):
424
423
if not isinstance (path_or_buf , HDFStore ):
425
424
# if there is an error, close the store if we opened it.
426
- try :
425
+ with suppress ( AttributeError ) :
427
426
store .close ()
428
- except AttributeError :
429
- pass
430
427
431
428
raise
432
429
@@ -763,10 +760,8 @@ def flush(self, fsync: bool = False):
763
760
if self ._handle is not None :
764
761
self ._handle .flush ()
765
762
if fsync :
766
- try :
763
+ with suppress ( OSError ) :
767
764
os .fsync (self ._handle .fileno ())
768
- except OSError :
769
- pass
770
765
771
766
def get (self , key : str ):
772
767
"""
@@ -3025,11 +3020,9 @@ def write_array(self, key: str, value: ArrayLike, items: Optional[Index] = None)
3025
3020
3026
3021
atom = None
3027
3022
if self ._filters is not None :
3028
- try :
3023
+ with suppress ( ValueError ) :
3029
3024
# get the atom for this datatype
3030
3025
atom = _tables ().Atom .from_dtype (value .dtype )
3031
- except ValueError :
3032
- pass
3033
3026
3034
3027
if atom is not None :
3035
3028
# We only get here if self._filters is non-None and
@@ -5046,14 +5039,12 @@ def _maybe_adjust_name(name: str, version) -> str:
5046
5039
-------
5047
5040
str
5048
5041
"""
5049
- try :
5042
+ with suppress ( IndexError ) :
5050
5043
if version [0 ] == 0 and version [1 ] <= 10 and version [2 ] == 0 :
5051
5044
m = re .search (r"values_block_(\d+)" , name )
5052
5045
if m :
5053
5046
grp = m .groups ()[0 ]
5054
5047
name = f"values_{ grp } "
5055
- except IndexError :
5056
- pass
5057
5048
return name
5058
5049
5059
5050
@@ -5143,7 +5134,7 @@ def __init__(
5143
5134
if is_list_like (where ):
5144
5135
5145
5136
# see if we have a passed coordinate like
5146
- try :
5137
+ with suppress ( ValueError ) :
5147
5138
inferred = lib .infer_dtype (where , skipna = False )
5148
5139
if inferred == "integer" or inferred == "boolean" :
5149
5140
where = np .asarray (where )
@@ -5163,9 +5154,6 @@ def __init__(
5163
5154
)
5164
5155
self .coordinates = where
5165
5156
5166
- except ValueError :
5167
- pass
5168
-
5169
5157
if self .coordinates is None :
5170
5158
5171
5159
self .terms = self .generate (where )
0 commit comments