Skip to content

Commit

Permalink
Fix deprecation, future and performance warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelosthege committed Apr 26, 2023
1 parent 01dff16 commit 357a15c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bletl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
NoMeasurementData,
)

__version__ = "1.2.2"
__version__ = "1.2.3"
7 changes: 5 additions & 2 deletions bletl/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ def from_bldata(
data["x"] = narrow[fs]
_log.info("Applying tsfresh extractor to %s\n", fs)
df_fs = ts_extractor._extract(data)
for i, mname in enumerate(df_fs.columns):
df_result[f"{fs}_{mname}"] = df_fs.to_numpy()[:, i]
# Rename columns to include the filterset name
df_fs.columns = [f"{fs}_{col}" for col in df_fs.columns]
# Add columns with new features for this filterset to the result
df_fs.index = [i for i, in df_fs.index]
df_result = pandas.concat([df_result, df_fs], axis=1)
_log.info("Extraction finished in: %s minutes", round((time.time() - s_time) / 60, ndigits=1))
return df_result
4 changes: 2 additions & 2 deletions bletl/splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ def get_mue(
if wells == "all":
wells = list(bsdata.time.columns)
if blank == "first":
blank_dict = {well: data.iloc[0] for well, data in bsdata.value.iteritems()}
blank_dict = {well: data.iloc[0] for well, data in bsdata.value.items()}
elif isinstance(blank, numbers.Number):
blank_dict = {well: blank for well, data in bsdata.value.iteritems()}
blank_dict = {well: blank for well, data in bsdata.value.items()}
elif isinstance(blank, dict):
if set(blank.keys()) != set(wells):
raise ValueError("Please provide blanks for every well")
Expand Down
9 changes: 4 additions & 5 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,10 @@ def test_get_unified_dataframe(self):
unified_df = data["BS20"].get_unified_dataframe()
assert isinstance(unified_df, pandas.DataFrame)
numpy.testing.assert_approx_equal(unified_df.index[2], 0.35313, significant=4)
numpy.testing.assert_approx_equal(
unified_df.iloc[unified_df.index.get_loc(5, method="nearest"), unified_df.columns.get_loc("A05")],
63.8517,
significant=6,
)
idx = unified_df.index.get_indexer([5], method="nearest")
col = unified_df.columns.get_indexer(["A05"])
values = unified_df.iloc[idx, col].to_numpy()
numpy.testing.assert_approx_equal(values, 63.8517, significant=6)

def test_get_narrow_data(self):
fp = pathlib.Path(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_get_mue_wells(self):

# dictionary of scalars (first 5 cycles)
blank_dict = {
well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.iteritems() if well in wells
well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.items() if well in wells
}
mue_blank_dict = bletl.splines.get_mue(bldata["BS3"], wells=wells, blank=blank_dict, method="us")
mue_median = numpy.median(mue_blank_dict.value.loc[60:75, "B03"])
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_get_mue_on_all(self):
numpy.testing.assert_allclose(mue_median, 0.30, atol=0.01)

# dictionary of scalars (first 5 cycles)
blank_dict = {well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.iteritems()}
blank_dict = {well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.items()}
mue_blank_dict = bletl.splines.get_mue(bldata["BS3"], blank=blank_dict, method="us")
mue_median = numpy.median(mue_blank_dict.value.loc[60:75, "B03"])
numpy.testing.assert_allclose(mue_median, 0.38, atol=0.02)
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_get_mue_wells(self):

# dictionary of scalars (first 5 cycles)
blank_dict = {
well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.iteritems() if well in wells
well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.items() if well in wells
}
mue_blank_dict = bletl.splines.get_mue(bldata["BS3"], wells=wells, blank=blank_dict, method="ucss")
mue_median = numpy.median(mue_blank_dict.value.loc[60:75, "B03"])
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_get_mue_on_all(self):
numpy.testing.assert_allclose(mue_median, 0.30, atol=0.02)

# dictionary of scalars (first 5 cycles)
blank_dict = {well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.iteritems()}
blank_dict = {well: data.iloc[:5].mean() for well, data in bldata["BS3"].value.items()}
mue_blank_dict = bletl.splines.get_mue(bldata["BS3"], blank=blank_dict, method="ucss")
mue_median = numpy.median(mue_blank_dict.value.loc[60:75, "B03"])
numpy.testing.assert_allclose(mue_median, 0.38, atol=0.02)
Expand Down

0 comments on commit 357a15c

Please sign in to comment.