Skip to content

Commit bb299a4

Browse files
committed
detect_objects: workaround for 'FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead', see pandas-dev/pandas#35407
1 parent 099ce2d commit bb299a4

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/detect_objects.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@
8585
raise Exception("Incompatible Metashape version: {} != {}".format(found_major_version, compatible_major_version))
8686

8787

88+
def pandas_append(df, row, ignore_index=False):
89+
import pandas as pd
90+
if isinstance(row, pd.DataFrame):
91+
result = pd.concat([df, row], ignore_index=ignore_index)
92+
elif isinstance(row, pd.core.series.Series):
93+
result = pd.concat([df, row.to_frame().T], ignore_index=ignore_index)
94+
elif isinstance(row, dict):
95+
result = pd.concat([df, pd.DataFrame(row, index=[0], columns=df.columns)])
96+
else:
97+
raise RuntimeError("pandas_append: unsupported row type - {}".format(type(row)))
98+
return result
99+
100+
88101
class DetectObjectsDlg(QtWidgets.QDialog):
89102

90103
def __init__(self, parent):
@@ -386,7 +399,7 @@ def train_on_user_data(self):
386399
cv2.imwrite(self.dir_train_subtiles + empty_tile_name, empty_tile)
387400

388401
# See https://github.com/weecology/DeepForest/issues/216
389-
all_annotations = all_annotations.append({'image_path': empty_tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)
402+
all_annotations = pandas_append(all_annotations, {'image_path': empty_tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)
390403

391404
nempty_tiles = 0
392405

@@ -483,10 +496,10 @@ def train_on_user_data(self):
483496

484497
nannotated_tiles += 1
485498
for (xmin, ymin), (xmax, ymax) in tile_annotations_version:
486-
all_annotations = all_annotations.append({'image_path': tile_name, 'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax, 'label': 'Tree'}, ignore_index=True)
499+
all_annotations = pandas_append(all_annotations, {'image_path': tile_name, 'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax, 'label': 'Tree'}, ignore_index=True)
487500
if len(tile_annotations_version) == 0:
488501
if self.tiles_without_annotations_supported:
489-
all_annotations = all_annotations.append({'image_path': tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)
502+
all_annotations = pandas_append(all_annotations, {'image_path': tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)
490503
nempty_tiles += 1
491504

492505
cv2.imwrite(self.dir_train_subtiles + tile_name, tile_version)
@@ -788,9 +801,9 @@ def detect(self):
788801
continue
789802
xmin, xmax = map(lambda x: fromx + x, [xmin, xmax])
790803
ymin, ymax = map(lambda y: fromy + y, [ymin, ymax])
791-
subtile_inner_trees_debug = subtile_inner_trees_debug.append(row, ignore_index=True)
804+
subtile_inner_trees_debug = pandas_append(subtile_inner_trees_debug, row, ignore_index=True)
792805
row.xmin, row.ymin, row.xmax, row.ymax = xmin, ymin, xmax, ymax
793-
subtile_inner_trees = subtile_inner_trees.append(row, ignore_index=True)
806+
subtile_inner_trees = pandas_append(subtile_inner_trees, row, ignore_index=True)
794807

795808
if self.debug_tiles:
796809
img_with_trees = self.debug_draw_trees(subtile, subtile_trees)
@@ -862,7 +875,7 @@ def detect(self):
862875
for idx, row in a.iterrows():
863876
if row.label == "Suppressed":
864877
continue
865-
big_tile_trees = big_tile_trees.append(row, ignore_index=True)
878+
big_tile_trees = pandas_append(big_tile_trees, row, ignore_index=True)
866879

867880
idx_on_borders = []
868881
for idx, rowA in big_tile_trees.iterrows():

0 commit comments

Comments
 (0)