Skip to content

Commit 7c1a365

Browse files
authored
Empty dataframe fix (#9)
* fix: migrating from setup.py to pyproject.toml * fix: updating to use map instead of applymap * fix: quick fix for returning empty dataframe when fault log is empty. Error message from eventlog is different to datacollection
1 parent c344ebb commit 7c1a365

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

LoopProjectFile/LoopProjectFileUtils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def ElementToDataframe(loopFilename, element, loopCompoundType):
306306
df = pandas.DataFrame.from_records(resp["value"], columns=columns)
307307
for name in columns:
308308
df[name] = df[name].astype(loopCompoundType[name])
309-
df = df.applymap(lambda x: x.decode() if isinstance(x, bytes) else x)
309+
df = df.map(lambda x: x.decode() if isinstance(x, bytes) else x)
310310
# df.set_index(columns[0], inplace=True)
311311
return df # .to_csv(outputFilename)
312312

@@ -383,9 +383,7 @@ def ToCsv(loopFilename, outputPath):
383383
print(" utm zone:", str(resp["value"]["utm"][0]) + utmNorthSouth)
384384
print(" easting: ", resp["value"]["utm"][2], "-", resp["value"]["utm"][3])
385385
print(" northing:", resp["value"]["utm"][4], "-", resp["value"]["utm"][5])
386-
print(
387-
" altitude:", resp["value"]["depth"][0], "-", resp["value"]["depth"][1]
388-
)
386+
print(" altitude:", resp["value"]["depth"][0], "-", resp["value"]["depth"][1])
389387
columns = [
390388
"minLong",
391389
"maxLong",
@@ -459,9 +457,7 @@ def ToCsv(loopFilename, outputPath):
459457
"foliationLog",
460458
LoopProjectFile.foliationEventType,
461459
)
462-
print(
463-
" Exporting foliation observations into", str(outputPath) + "foliationObs.csv"
464-
)
460+
print(" Exporting foliation observations into", str(outputPath) + "foliationObs.csv")
465461
ElementToCsv(
466462
loopFilename,
467463
outputPath + "foliationObs.csv",

LoopProjectFile/projectfile.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ def _add_names_to_df(self, log, df):
116116
"""
117117
df["name"] = "none"
118118
for stratigraphic_id in log.index:
119-
df.loc[df["layerId"] == stratigraphic_id, "name"] = log.loc[
120-
stratigraphic_id, "name"
121-
]
119+
df.loc[df["layerId"] == stratigraphic_id, "name"] = log.loc[stratigraphic_id, "name"]
122120

123121
@property
124122
def extents(self) -> np.ndarray:
@@ -328,10 +326,7 @@ def stratigraphyLocations(self, value: pd.DataFrame):
328326
raise TypeError("stratigraphyLocations must be set with a pandas dataframe")
329327
self._validate_data_frame_columns(
330328
value,
331-
{
332-
k: False
333-
for k in ["layerId", "easting", "northing", "altitude", "type", "name"]
334-
},
329+
{k: False for k in ["layerId", "easting", "northing", "altitude", "type", "name"]},
335330
)
336331
self.__setitem__("contacts", value)
337332

@@ -344,9 +339,7 @@ def stratigraphyOrientations(self) -> pd.DataFrame:
344339
@stratigraphyOrientations.setter
345340
def stratigraphyOrientations(self, value: pd.DataFrame):
346341
if isinstance(value, pd.DataFrame) is False:
347-
raise TypeError(
348-
"stratigraphyOrientations must be set with a pandas dataframe"
349-
)
342+
raise TypeError("stratigraphyOrientations must be set with a pandas dataframe")
350343
self._validate_data_frame_columns(
351344
value,
352345
{
@@ -388,6 +381,13 @@ def __getitem__(self, element):
388381
# TODO: this isn't really ideal and maybe need to be removed but at least it gives an idea of the column
389382
# names needed.
390383
return pd.DataFrame(columns=list(compoundTypeMap[element].names))
384+
if (
385+
resp["errorString"]
386+
== "No EventLog present in ExtractedInformation for access request"
387+
):
388+
# TODO: this isn't really ideal and maybe need to be removed but at least it gives an idea of the column
389+
# names needed.
390+
return pd.DataFrame(columns=list(compoundTypeMap[element].names))
391391
# return ProjectFileElement(self.project_filename, element).value
392392

393393
def __setitem__(self, element, value):

0 commit comments

Comments
 (0)