diff --git a/src/dx/formatters/main.py b/src/dx/formatters/main.py index 185b7822..a46d9376 100644 --- a/src/dx/formatters/main.py +++ b/src/dx/formatters/main.py @@ -74,8 +74,7 @@ def handle_format( ipython = ipython_shell or get_ipython() logger.debug(f"*** handling {settings.DISPLAY_MODE} format for {type(obj)=} ***") - if not isinstance(obj, pd.DataFrame): - obj = to_dataframe(obj) + obj = to_dataframe(obj) # ensure we aren't mutating the original dataframe df = obj.copy() diff --git a/src/dx/utils/formatting.py b/src/dx/utils/formatting.py index a1a4d500..1df7dd60 100644 --- a/src/dx/utils/formatting.py +++ b/src/dx/utils/formatting.py @@ -14,6 +14,9 @@ def to_dataframe(obj) -> pd.DataFrame: """ Converts an object to a pandas dataframe. """ + if isinstance(obj, pd.DataFrame): + return obj + logger.debug(f"converting {type(obj)} to pd.DataFrame") # handling for groupby operations returning pd.Series @@ -258,7 +261,7 @@ def clean_series_values(s: pd.Series) -> pd.Series: """ dtype_str = str(s.dtype) - if dtype_str in {"float", "int", "bool"}: + if dtype_str in {"float64", "int64", "bool"}: # skip standard dtypes logger.debug(f"skipping `{s.name}` since it has dtype `{dtype_str}`") return s