in tzrec/tools/tdm/gen_tree/tree_builder.py [0:0]
def _column_modes(self, matrix: List[List[pa.Scalar]]) -> List[pa.Scalar]:
transposed_matrix = list(zip(*matrix))
modes = []
for column in transposed_matrix:
if pa.types.is_string(column[0].type):
filtered_column = [x for x in column if x]
if filtered_column:
most_common = Counter(filtered_column).most_common(1)[0][0]
modes.append(most_common)
else:
modes.append(pa.scalar(""))
else:
mode = pc.mode(list(column))
if len(mode) > 0:
modes.append(mode[0][0])
else:
# null value with column dtype
modes.append(column[0])
return modes