Skip to content

Commit d750e00

Browse files
alexbarrosaquemy
authored andcommitted
fix: infer all Numeric vars as TimeSeries when tsmode=True (#1343)
* fix: infer all numericals as ts when tsmode=True * fix: adjust unit tests * fix: ts typeset allowing constant values
1 parent 25d3946 commit d750e00

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/ydata_profiling/model/typeset.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,11 @@ def get_relations() -> Sequence[TypeRelation]:
293293
@series_not_empty
294294
@series_handle_nulls
295295
def contains_op(series: pd.Series, state: dict) -> bool:
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)
296+
return (
297+
pdt.is_numeric_dtype(series)
298+
and not pdt.is_bool_dtype(series)
299+
and series.nunique() > 1
300+
)
310301

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

tests/unit/test_time_series.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ 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)],
2928
"gaussian": [round(x, 2) for x in np.random.normal(0, 1, size)],
3029
}
3130
)
@@ -37,7 +36,7 @@ def html_profile() -> str:
3736
def test_timeseries_identification(html_profile: str):
3837
assert "<th>TimeSeries</th>" in html_profile, "TimeSeries not detected"
3938
assert (
40-
"<tr><th>TimeSeries</th><td>8</td></tr>" in html_profile
39+
"<tr><th>TimeSeries</th><td>9</td></tr>" in html_profile
4140
), "TimeSeries incorrectly identified"
4241

4342

@@ -46,7 +45,7 @@ def test_timeseries_autocorrelation_tab(html_profile: str):
4645
"role=tab data-toggle=tab>Autocorrelation<" in html_profile
4746
), "TimeSeries not detected"
4847
assert (
49-
html_profile.count("role=tab data-toggle=tab>Autocorrelation<") == 8
48+
html_profile.count("role=tab data-toggle=tab>Autocorrelation<") == 9
5049
), "TimeSeries autocorrelation tabs incorrectly generated"
5150

5251

0 commit comments

Comments
 (0)