From ed0c93208f5a5ce3b62d5c619e3fd6aa34158b35 Mon Sep 17 00:00:00 2001 From: Brad Liang Date: Thu, 4 Nov 2021 09:01:34 -0700 Subject: [PATCH] fix: add static typing for class methods, resolve pandas futurewarning --- gamry_parser/chronoa.py | 4 ++-- gamry_parser/cv.py | 2 +- gamry_parser/eispot.py | 2 +- gamry_parser/gamryparser.py | 16 +++++++++------- gamry_parser/ocp.py | 2 +- gamry_parser/vfp600.py | 10 +++++----- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/gamry_parser/chronoa.py b/gamry_parser/chronoa.py index f37e9a4..f5e86e0 100644 --- a/gamry_parser/chronoa.py +++ b/gamry_parser/chronoa.py @@ -6,7 +6,7 @@ class ChronoAmperometry(parser.GamryParser): """Load a ChronoAmperometry experiment generated in Gamry EXPLAIN format.""" - def get_curve_data(self, curve=0): + def get_curve_data(self, curve: int = 0): """retrieve chronoamperometry experiment data Args: @@ -37,7 +37,7 @@ def get_sample_time(self): assert self.loaded, "DTA file not loaded. Run ChronoAmperometry.load()" return self.header["SAMPLETIME"] - def get_sample_count(self, curve=0): + def get_sample_count(self, curve: int = 0): """compute the number of samples collected for the loaded chronoamperometry experiment Args: diff --git a/gamry_parser/cv.py b/gamry_parser/cv.py index 6e1825d..127b40e 100644 --- a/gamry_parser/cv.py +++ b/gamry_parser/cv.py @@ -42,7 +42,7 @@ def get_scan_rate(self): ), "DTA header file missing SCANRATE specification" return self.header["SCANRATE"] - def get_curve_data(self, curve=0): + def get_curve_data(self, curve: int = 0): """retrieve relevant cyclic voltammetry experimental data Args: diff --git a/gamry_parser/eispot.py b/gamry_parser/eispot.py index 0c77471..5fba0f2 100644 --- a/gamry_parser/eispot.py +++ b/gamry_parser/eispot.py @@ -4,7 +4,7 @@ class Impedance(parser.GamryParser): """Load a Potentiostatic EIS experiment generated in Gamry EXPLAIN format.""" - def get_curve_data(self, curve=0): + def get_curve_data(self, curve: int = 0): """retrieve potentiostatic eis-relevant data Args: diff --git a/gamry_parser/gamryparser.py b/gamry_parser/gamryparser.py index f7b8cf9..f813778 100644 --- a/gamry_parser/gamryparser.py +++ b/gamry_parser/gamryparser.py @@ -39,7 +39,7 @@ def __init__(self, filename=None, to_timestamp=None): "CV": {"Vf": "V vs. Ref.", "Im": "A"}, } - def load(self, filename=None, to_timestamp=None): + def load(self, filename: str = None, to_timestamp: bool = None): """save experiment information to \"header\", then save curve data to \"curves\" Args: @@ -96,7 +96,7 @@ def get_curve_numbers(self): assert self.loaded, "DTA file not loaded. Run GamryParser.load()" return tuple(range(1, self.curve_count + 1)) - def get_curve_data(self, curve=0): + def get_curve_data(self, curve: int = 0): """retrieve relevant experimental data Args: @@ -162,7 +162,7 @@ def read_header(self): """ pos = 0 - with open(self.fname, "r", encoding="utf8", errors="ignore") as f: + with open(file=self.fname, mode="r", encoding="utf8", errors="ignore") as f: cur_line = f.readline().split("\t") while not re.search(r"(^|Z|VFP|EFM)CURVE", cur_line[0]): if f.tell() == pos: @@ -206,7 +206,9 @@ def read_header(self): f.readline() # skip second line of header for _ in range(n_points): ocv += f.readline().strip() + "\n" - ocv = pd.read_csv(StringIO(ocv), "\t", header=0, index_col=0) + ocv = pd.read_csv( + StringIO(ocv), delimiter="\t", header=0, index_col=0 + ) self.ocv = ocv self.ocv_exists = True @@ -214,7 +216,7 @@ def read_header(self): return self.header, self.header_length - def read_curve_data(self, fid): + def read_curve_data(self, fid: int): """helper function to process an EXPLAIN Table Args: @@ -239,7 +241,7 @@ def read_curve_data(self, fid): if fid.tell() == pos: break - curve = pd.read_csv(StringIO(curve), "\t", header=0, index_col=0) + curve = pd.read_csv(StringIO(curve), delimiter="\t", header=0, index_col=0) keys = curve.columns.values.tolist() units = units[1:] @@ -261,7 +263,7 @@ def read_curves(self): self.curves = [] self.curve_count = 0 - with open(self.fname, "r", encoding="utf8", errors="ignore") as f: + with open(file=self.fname, mode="r", encoding="utf8", errors="ignore") as f: f.seek(self.header_length) # skip to end of header while True: diff --git a/gamry_parser/ocp.py b/gamry_parser/ocp.py index 09db63d..662a2e9 100644 --- a/gamry_parser/ocp.py +++ b/gamry_parser/ocp.py @@ -24,7 +24,7 @@ def get_curve_data(self): df = self.curves[0] return df[["T", "Vf"]] - def load(self, filename=None, to_timestamp=None): + def load(self, filename: str = None, to_timestamp: bool = None): """save experiment information to \"header\", then save curve data to \"curves\" Args: diff --git a/gamry_parser/vfp600.py b/gamry_parser/vfp600.py index 212797b..a6cf6a8 100644 --- a/gamry_parser/vfp600.py +++ b/gamry_parser/vfp600.py @@ -7,7 +7,7 @@ class VFP600(parser.GamryParser): """Load experiment data generated by Gamry VFP600 software (expected in EXPLAIN format, including header)""" - def __init__(self, filename=None, to_timestamp=None): + def __init__(self, filename: str = None, to_timestamp: bool = None): """VFP600.__init__ Args: @@ -20,7 +20,7 @@ def __init__(self, filename=None, to_timestamp=None): # No information about experiment time is available with VFP600 files, so no conversion of samples to pd.Timestamp is possible. super().__init__(filename=filename, to_timestamp=False) - def load(self, filename=None): + def load(self, filename: str = None): """save experiment information to \"header\", then save curve data to \"curves\" Args: @@ -65,7 +65,7 @@ def get_sample_time(self): assert self.loaded, "DTA file not loaded. Run ChronoAmperometry.load()" return 1 / self.header["FREQ"] - def get_sample_count(self, curve=0): + def get_sample_count(self, curve: int = 0): """compute the number of samples collected for the loaded chronoamperometry experiment Args: @@ -79,7 +79,7 @@ def get_sample_count(self, curve=0): assert self.loaded, "DTA file not loaded. Run ChronoAmperometry.load()" return len(self.curves[curve - 1].index) - def read_curve_data(self, fid): + def read_curve_data(self, fid: int): """helper function to process an EXPLAIN Table Args: @@ -104,7 +104,7 @@ def read_curve_data(self, fid): if fid.tell() == pos: break - curve = pd.read_csv(StringIO(curve), "\t", header=0) + curve = pd.read_csv(StringIO(curve), delimiter="\t", header=0) keys = curve.columns.values.tolist() units = units[1:]