Skip to content

Commit

Permalink
#823: wrap skew/kurtosis calculations in try/except for pyarrow
Browse files Browse the repository at this point in the history
  • Loading branch information
aschonfeld committed Nov 29, 2023
1 parent 6173960 commit 67fac74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 12 additions & 0 deletions dtale/pandas_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pandas as pd

from logging import getLogger
from pkg_resources import parse_version

logger = getLogger(__name__)


def check_pandas_version(version_number):
return parse_version(pd.__version__) >= parse_version(version_number)
Expand All @@ -27,3 +30,12 @@ def groupby_code(index, dropna=True):

def is_pandas2():
return check_pandas_version("2.0.0")


def run_function(obj, calc_name):
try:
if hasattr(obj, calc_name):
return getattr(obj, calc_name)()
except BaseException as ex:
logger.debug("Could not execute {} function: {}".format(calc_name, ex))
return None
20 changes: 12 additions & 8 deletions dtale/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,12 @@ def _formatter(col_index, col):
if not any((np.isnan(v) or np.isinf(v) for v in [o_s, o_e])):
dtype_data["hasOutliers"] += int(((s < o_s) | (s > o_e)).sum())
dtype_data["outlierRange"] = dict(lower=o_s, upper=o_e)
if hasattr(s, "skew"):
dtype_data["skew"] = json_float(s.skew())
if hasattr(s, "kurt"):
dtype_data["kurt"] = json_float(s.kurt())
skew_val = pandas_util.run_function(s, "skew")
if skew_val is not None:
dtype_data["skew"] = json_float(skew_val)
kurt_val = pandas_util.run_function(s, "kurt")
if kurt_val is not None:
dtype_data["kurt"] = json_float(kurt_val)

if classification in ["F", "I"] and not s.isnull().all():
# build variance flag
Expand All @@ -761,10 +763,12 @@ def _formatter(col_index, col):

if classification in ["D"] and not s.isnull().all():
timestamps = apply(s, lambda x: json_timestamp(x, np.nan))
if hasattr(timestamps, "skew"):
dtype_data["skew"] = json_float(timestamps.skew())
if hasattr(timestamps, "kurt"):
dtype_data["kurt"] = json_float(timestamps.kurt())
skew_val = pandas_util.run_function(timestamps, "skew")
if skew_val is not None:
dtype_data["skew"] = json_float(skew_val)
kurt_val = pandas_util.run_function(timestamps, "kurt")
if kurt_val is not None:
dtype_data["kurt"] = json_float(kurt_val)

if classification == "S" and not dtype_data["hasMissing"]:
if (
Expand Down

0 comments on commit 67fac74

Please sign in to comment.