Repository: evidentlyai/evidently
Issue: Error generating DataQualityPreset report with datetime column mapping and no reference dataset
Root cause: Validation Gap

I tried the DataQualityPreset test case with a datetime column mapping and no reference dataset.

The report failed with following error:
```
cls = <class 'evidently.metric_results.HistogramData'>, value = None

    @classmethod
    def from_df(cls, value: pd.DataFrame):
>       return cls(x=value["x"], count=value["count"])
E       TypeError: 'NoneType' object is not subscriptable
```


Here is a test case:

```
import json
from typing import Optional

import numpy as np
import pandas as pd
import pytest

from evidently.metric_preset import DataQualityPreset
from evidently.pipeline.column_mapping import ColumnMapping
from evidently.report import Report


@pytest.mark.parametrize(
    "current_data, reference_data, metric, column_mapping",
    (
        (
            pd.DataFrame(
                {
                    "my_target": [1, 2, 3],
                    "prediction": [1, 2, 3],
                    "feature1": [1, 2, 3],
                    "feature2": ["a", "b", "c"],
                    "datetime": pd.date_range("2020-01-01", periods=3),
                }
            ),
            None,
            DataQualityPreset(columns=["feature1", "feature2"]),
            ColumnMapping(
                target="my_target",
                datetime="datetime"
            ),
        ),
        (
            pd.DataFrame(
                {
                    "myid": "some_id",
                    "my_target": [1, 2, 3],
                    "prediction": [1, 2, 3],
                    "feature1": [1, 2, 3],
                    "feature2": ["a", "b", "c"],
                    "datetime": pd.date_range("2020-01-01", periods=3),
                }
            ),
            None,
            DataQualityPreset(),
            ColumnMapping(
                target="my_target",
                id="myid",
                prediction="prediction",
                datetime="datetime",
            ),
        ),
    ),
)
def test_data_quality_preset(
    current_data: pd.DataFrame,
    reference_data: Optional[pd.DataFrame],
    metric: DataQualityPreset,
    column_mapping: ColumnMapping,
) -> None:
    report = Report(metrics=[metric])
    report.run(current_data=current_data, reference_data=reference_data, column_mapping=column_mapping)
    report.save_html('/tmp/test.html')
```

The issue seems to be in the calculations/data_quality.py module

```
    elif column_type == ColumnType.Datetime:
        prefix, freq = choose_agg_period(current_data, reference_data)
        curr_data = current_data.dt.to_period(freq=freq).value_counts().reset_index()
        curr_data.columns = ["x", "number_of_items"]
        curr_data["x"] = curr_data["x"].dt.to_timestamp()
        reference = None
        if reference_data is not None:
            ref_data = reference_data.dt.to_period(freq=freq).value_counts().reset_index()
            ref_data.columns = ["x", "number_of_items"]
            ref_data["x"] = ref_data["x"].dt.to_timestamp()
            max_ref_date = ref_data["x"].max()
            min_curr_date = curr_data["x"].min()
            if max_ref_date == min_curr_date:
                curr_data, ref_data = _split_periods(curr_data, ref_data, "x")
            reference = ref_data
            reference.columns = ["x", "count"]
        curr_data.columns = ["x", "count"]
        data_hist = Histogram(current=HistogramData.from_df(curr_data), reference=HistogramData.from_df(reference))
```

reference is None. Hence the HistogramData.from_df(reference) is throwing the exception.

Thank you for reporting the bug @venkat1m!