Skip to content

Commit

Permalink
fix: add static typing for class methods, resolve pandas futurewarning
Browse files Browse the repository at this point in the history
  • Loading branch information
bcliang committed Nov 4, 2021
1 parent 400b5e9 commit ed0c932
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions gamry_parser/chronoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion gamry_parser/cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion gamry_parser/eispot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions gamry_parser/gamryparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -206,15 +206,17 @@ 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

self.header_length = f.tell()

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:
Expand All @@ -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:]

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion gamry_parser/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions gamry_parser/vfp600.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:]

Expand Down

0 comments on commit ed0c932

Please sign in to comment.