def _order_csv_by_filenames(self, path_to_embeddings_csv: str) -> List[str]:
        """Orders the rows in a csv according to the order specified on the server and saves it as a new file.

        Args:
            path_to_embeddings_csv:
                the path to the csv to order

        Returns:
            the filepath to the new csv

        """
        with open(path_to_embeddings_csv, "r") as f:
            data = csv.reader(f)

            rows = list(data)
            header_row = rows[0]
            rows_without_header = rows[1:]
            index_filenames = header_row.index("filenames")
            filenames = [row[index_filenames] for row in rows_without_header]

            filenames_on_server = self.get_filenames()

            if len(filenames) != len(filenames_on_server):
                raise ValueError(
                    f"There are {len(filenames)} rows in the embedding file, but "
                    f"{len(filenames_on_server)} filenames/samples on the server."
                )
            if set(filenames) != set(filenames_on_server):
                raise ValueError(
                    f"The filenames in the embedding file and "
                    f"the filenames on the server do not align"
                )

            rows_without_header_ordered = self._order_list_by_filenames(
                filenames, rows_without_header
            )

            rows_csv = [header_row]
            rows_csv += rows_without_header_ordered

        return rows_csv
Orders the rows in a csv according to the order specified on the server and saves it as a new file.

        Args:
            path_to_embeddings_csv:
                the path to the csv to order

        Returns:
            the filepath to the new csv

        
lightly/api/api_workflow_upload_embeddings.py