Skip to content

Commit 67fac74

Browse files
committed
#823: wrap skew/kurtosis calculations in try/except for pyarrow
1 parent 6173960 commit 67fac74

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

dtale/pandas_util.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import pandas as pd
22

3+
from logging import getLogger
34
from pkg_resources import parse_version
45

6+
logger = getLogger(__name__)
7+
58

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

2831
def is_pandas2():
2932
return check_pandas_version("2.0.0")
33+
34+
35+
def run_function(obj, calc_name):
36+
try:
37+
if hasattr(obj, calc_name):
38+
return getattr(obj, calc_name)()
39+
except BaseException as ex:
40+
logger.debug("Could not execute {} function: {}".format(calc_name, ex))
41+
return None

dtale/views.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,12 @@ def _formatter(col_index, col):
743743
if not any((np.isnan(v) or np.isinf(v) for v in [o_s, o_e])):
744744
dtype_data["hasOutliers"] += int(((s < o_s) | (s > o_e)).sum())
745745
dtype_data["outlierRange"] = dict(lower=o_s, upper=o_e)
746-
if hasattr(s, "skew"):
747-
dtype_data["skew"] = json_float(s.skew())
748-
if hasattr(s, "kurt"):
749-
dtype_data["kurt"] = json_float(s.kurt())
746+
skew_val = pandas_util.run_function(s, "skew")
747+
if skew_val is not None:
748+
dtype_data["skew"] = json_float(skew_val)
749+
kurt_val = pandas_util.run_function(s, "kurt")
750+
if kurt_val is not None:
751+
dtype_data["kurt"] = json_float(kurt_val)
750752

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

762764
if classification in ["D"] and not s.isnull().all():
763765
timestamps = apply(s, lambda x: json_timestamp(x, np.nan))
764-
if hasattr(timestamps, "skew"):
765-
dtype_data["skew"] = json_float(timestamps.skew())
766-
if hasattr(timestamps, "kurt"):
767-
dtype_data["kurt"] = json_float(timestamps.kurt())
766+
skew_val = pandas_util.run_function(timestamps, "skew")
767+
if skew_val is not None:
768+
dtype_data["skew"] = json_float(skew_val)
769+
kurt_val = pandas_util.run_function(timestamps, "kurt")
770+
if kurt_val is not None:
771+
dtype_data["kurt"] = json_float(kurt_val)
768772

769773
if classification == "S" and not dtype_data["hasMissing"]:
770774
if (

0 commit comments

Comments
 (0)