10000 BUG: Have np.ma.dump and np.ma.load close their files (#10055) · numpy/numpy@eac6056 · GitHub
[go: up one dir, main page]

Skip to content

Commit eac6056

Browse files
orbit-stabilizereric-wieser
authored andcommitted
BUG: Have np.ma.dump and np.ma.load close their files (#10055)
Fixes #10045
1 parent 37cf914 commit eac6056

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

numpy/ma/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7818,8 +7818,10 @@ def dump(a, F):
78187818
78197819
"""
78207820
if not hasattr(F, 'readline'):
7821-
F = open(F, 'w')
7822-
return pickle.dump(a, F)
7821+
with open(F, 'w') as F:
7822+
pickle.dump(a, F)
7823+
else:
7824+
pickle.dump(a, F)
78237825

78247826

78257827
def dumps(a):
@@ -7859,8 +7861,10 @@ def load(F):
78597861
78607862
"""
78617863
if not hasattr(F, 'readline'):
7862-
F = open(F, 'r')
7863-
return pickle.load(F)
7864+
with open(F, 'r') as F:
7865+
pickle.load(F)
7866+
else:
7867+
pickle.load(F)
78647868

78657869

78667870
def loads(strg):

0 commit comments

Comments
 (0)
0