Skip to content

Commit

Permalink
remove excess conversions to pd.Dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
shouples committed Nov 14, 2023
1 parent 61e843a commit 4fa3dcb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/dx/formatters/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,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()
Expand Down
5 changes: 4 additions & 1 deletion src/dx/utils/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4fa3dcb

Please sign in to comment.