df_wrapper_base.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from __future__ import annotations
  10. from collections.abc import Iterable
  11. from pathlib import Path
  12. import pandas as pd
  13. class DfWrapperBase:
  14. """Wrapper for data frames."""
  15. def __init__(self, data: pd.DataFrame):
  16. self.data = data
  17. def length(self) -> int:
  18. return len(self.data.index)
  19. def has_values(self) -> bool:
  20. return self.length() > 0
  21. def to_csv(self, file_path: Path) -> None:
  22. self.data.to_csv(file_path)
  23. def concat_df_wrapper_data(wrappers: Iterable[DfWrapperBase]) -> pd.DataFrame:
  24. return pd.concat(
  25. [wrapper.data for wrapper in wrappers],
  26. ignore_index=True,
  27. )