From c50adb382aacfc377255589c64bfd8fdee12ba12 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 14 Feb 2023 21:44:46 +0200 Subject: [PATCH] Lazily import pandas to speedup non-pandas use --- tabledata/_core.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tabledata/_core.py b/tabledata/_core.py index 68d47e5..acfbd6a 100644 --- a/tabledata/_core.py +++ b/tabledata/_core.py @@ -17,14 +17,6 @@ from ._logger import logger -try: - from pandas import DataFrame - - INSTALLED_PANDAS = True -except ImportError: - INSTALLED_PANDAS = False - - class TableData: """ Class to represent a table data structure. @@ -428,7 +420,9 @@ def as_dataframe(self) -> "DataFrame": - `pandas `__ """ - if not INSTALLED_PANDAS: + try: + from pandas import DataFrame + except ImportError: raise RuntimeError("required 'pandas' package to execute as_dataframe method") dataframe = DataFrame(self.value_matrix)