Skip to content

Commit

Permalink
TST: ensure file handles get closed
Browse files Browse the repository at this point in the history
  • Loading branch information
rgommers committed Feb 21, 2024
1 parent 3b743b5 commit f2d8a9c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pywt/data/_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def ascent():
"""
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ascent.npz')
ascent = np.load(fname)['data']
with open(fname, 'rb') as f:
ascent = np.load(f)['data']

return ascent


Expand Down Expand Up @@ -72,7 +74,9 @@ def aero():
"""
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'aero.npz')
aero = np.load(fname)['data']
with open(fname, 'rb') as f:
aero = np.load(f)['data']

return aero


Expand Down Expand Up @@ -118,7 +122,9 @@ def camera():
"""
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'camera.npz')
camera = np.load(fname)['data']
with open(fname, 'rb') as f:
camera = np.load(f)['data']

return camera


Expand Down Expand Up @@ -148,7 +154,9 @@ def ecg():
>>> plt.show() # doctest: +SKIP
"""
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ecg.npy')
ecg = np.load(fname)
with open(fname, 'rb') as f:
ecg = np.load(f)

return ecg


Expand Down Expand Up @@ -184,7 +192,9 @@ def nino():
>>> plt.show() # doctest: +SKIP
"""
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sst_nino3.npy')
sst_csv = np.load(fname)
with open(fname, 'rb') as f:
sst_csv = np.load(f)

# sst_csv = pd.read_csv("http://www.cpc.ncep.noaa.gov/data/indices/ersst4.nino.mth.81-10.ascii", sep=' ', skipinitialspace=True)
# take only full years
n = int(np.floor(sst_csv.shape[0]/12.)*12.)
Expand Down

0 comments on commit f2d8a9c

Please sign in to comment.