2323from numbers import Integral , Number
2424from xml .etree import ElementTree
2525
26- import matplotlib .cm as mcm
2726import matplotlib as mpl
27+ import matplotlib .cm as mcm
2828import matplotlib .colors as mcolors
2929import numpy as np
3030import numpy .ma as ma
@@ -44,12 +44,12 @@ def _cycle_handler(value):
4444
4545rc .register_handler ("cycle" , _cycle_handler )
4646
47- from .internals import ic # noqa: F401
4847from .internals import (
4948 _kwargs_to_args ,
5049 _not_none ,
5150 _pop_props ,
5251 docstring ,
52+ ic , # noqa: F401
5353 inputs ,
5454 warnings ,
5555)
@@ -910,11 +910,12 @@ def _warn_or_raise(descrip, error=RuntimeError):
910910 # NOTE: This appears to be biggest import time bottleneck! Increases
911911 # time from 0.05s to 0.2s, with numpy loadtxt or with this regex thing.
912912 delim = re .compile (r"[,\s]+" )
913- data = [
914- delim .split (line .strip ())
915- for line in open (path )
916- if line .strip () and line .strip ()[0 ] != "#"
917- ]
913+ with open (path ) as f :
914+ data = [
915+ delim .split (line .strip ())
916+ for line in f
917+ if line .strip () and line .strip ()[0 ] != "#"
918+ ]
918919 try :
919920 data = [[float (num ) for num in line ] for line in data ]
920921 except ValueError :
@@ -966,7 +967,8 @@ def _warn_or_raise(descrip, error=RuntimeError):
966967 # Read hex strings
967968 elif ext == "hex" :
968969 # Read arbitrary format
969- string = open (path ).read () # into single string
970+ with open (path ) as f :
971+ string = f .read () # into single string
970972 data = REGEX_HEX_MULTI .findall (string )
971973 if len (data ) < 2 :
972974 return _warn_or_raise ("Failed to find 6-digit or 8-digit HEX strings." )
0 commit comments