Skip to content

Commit 40fb0c2

Browse files
committed
fix: revert infer all Numeric vars as TimeSeries when tsmode=True (#1343)" (#1346)
This reverts commit ba957be.
1 parent caec7f0 commit 40fb0c2

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/ydata_profiling/model/typeset.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,20 @@ def get_relations() -> Sequence[TypeRelation]:
293293
@series_not_empty
294294
@series_handle_nulls
295295
def contains_op(series: pd.Series, state: dict) -> bool:
296-
return (
297-
pdt.is_numeric_dtype(series)
298-
and not pdt.is_bool_dtype(series)
299-
and series.nunique() > 1
300-
)
296+
def is_timedependent(series: pd.Series) -> bool:
297+
autocorrelation_threshold = config.vars.timeseries.autocorrelation
298+
lags = config.vars.timeseries.lags
299+
with warnings.catch_warnings():
300+
warnings.simplefilter("ignore", RuntimeWarning)
301+
for lag in lags:
302+
autcorr = series.autocorr(lag=lag)
303+
if autcorr >= autocorrelation_threshold:
304+
return True
305+
306+
return False
307+
308+
is_numeric = pdt.is_numeric_dtype(series) and not pdt.is_bool_dtype(series)
309+
return is_numeric and is_timedependent(series)
301310

302311
types = {Unsupported, Boolean, Numeric, Text, Categorical, DateTime}
303312
if config.vars.path.active:

tests/unit/test_time_series.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def html_profile() -> str:
2525
"constant": np.ones(size),
2626
"sin": [round(np.sin(x * np.pi / 180), 2) for x in time_steps],
2727
"cos": [round(np.cos(x * np.pi / 180), 2) for x in time_steps],
28+
"uniform": [round(x, 2) for x in np.random.uniform(0, 10, size)],
2829
"gaussian": [round(x, 2) for x in np.random.normal(0, 1, size)],
2930
}
3031
)
@@ -36,7 +37,7 @@ def html_profile() -> str:
3637
def test_timeseries_identification(html_profile: str):
3738
assert "<th>TimeSeries</th>" in html_profile, "TimeSeries not detected"
3839
assert (
39-
"<tr><th>TimeSeries</th><td>9</td></tr>" in html_profile
40+
"<tr><th>TimeSeries</th><td>8</td></tr>" in html_profile
4041
), "TimeSeries incorrectly identified"
4142

4243

@@ -45,7 +46,7 @@ def test_timeseries_autocorrelation_tab(html_profile: str):
4546
"role=tab data-toggle=tab>Autocorrelation<" in html_profile
4647
), "TimeSeries not detected"
4748
assert (
48-
html_profile.count("role=tab data-toggle=tab>Autocorrelation<") == 9
49+
html_profile.count("role=tab data-toggle=tab>Autocorrelation<") == 8
4950
), "TimeSeries autocorrelation tabs incorrectly generated"
5051

5152

0 commit comments

Comments
 (0)