Repository: ydataai/ydata-profiling

Issue:
ExpectationProfiler fails to profile a datetime column
**Describe the bug**
I've encountered the following `TypeError` when trying to profile a dataframe that has a datetime column
<details><summary>Click to expand <strong><em>Traceback</em></strong></summary>

```python

profile.to_expectation_suite(suite_name=f"{schema}.{table}")
[03/11/21 14:49:33] INFO     INFO - 2021-03-11 14:49:33,088 - utils.py - NumExpr utils.py:157
                             defaulting to 4 threads.                                        
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/ds-vroom-demand/great_expectations/uncommitted/test_profile.py in 
----> 15 profile.to_expectation_suite(suite_name=f"{schema}.{table}")

~/.pyenv/versions/vroom/lib/python3.7/site-packages/pandas_profiling/expectations_report.py in to_expectation_suite(self, suite_name, data_context, save_suite, run_validation, build_data_docs, handler)
     88         # Dispatch to expectations per semantic variable type
     89         for name, variable_summary in summary["variables"].items():
---> 90             handler.handle(variable_summary["type"], name, variable_summary, batch)
     91 
     92         # We don't actually update the suite object on the batch in place, so need

...
~/.pyenv/versions/vroom/lib/python3.7/site-packages/great_expectations/dataset/pandas_dataset.py in is_between(val)
   1223                     ):
   1224                         raise TypeError(
-> 1225                             "Column values, min_value, and max_value must either be None or of the same type."
   1226                         )
   1227 

```
</details>

```python
TypeError: Column values, min_value, and max_value must either be None or of the same type.
```

From looking at the arguments to `is_between` in `great_expectations.dataset.pandas_dataset.py`, this seems to be due to `min_value` and `max_value` being serialised to their string representations, but the column itself doesn't.

I think this can be resolved by modifying the arguments to `datetime_expectations` in `pandas_profiling.model.expectation_algorithms` as follows 

```python
def datetime_expectations(name, summary, batch, *args):
    if any(k in summary for k in ["min", "max"]):
        batch.expect_column_values_to_be_between(
            name, min_value=summary.get("min"), max_value=summary.get("max"), parse_strings_as_datetimes=True
        )

    return name, summary, batch
```
I've been able to resolve this issue myself by altering that function. I'm happy to submit this as a PR if this is acceptable.

**To Reproduce**
```python
"""
Test for issue XXX:
https://github.com/pandas-profiling/pandas-profiling/issues/XXX
"""
import pandas as pd
import pandas_profiling


def test_issueXXX():
    df = pd.DataFrame({'date':pd.date_range('2021-01-01', '2021-03-01', freq='d')})
    profile = pandas_profiling.ProfileReport(df=df, explorative=True)
    profile.to_expectation_suite(suite_name='test',   save_suite=False, build_data_docs=False, run_validation=False)
  
```

**Version information:**

* _Python version_: 3.7.6
* _Environment_: Pycharm
* _`pip`_: 

<details><summary>Click to expand <strong><em>Version information</em></strong></summary>
<p>

```
alembic==1.4.1
altair==4.1.0
appnope==0.1.2
argon2-cffi==20.1.0
arrow==0.17.0
astor==0.8.1
async-generator==1.10
attrs==20.3.0
azure-core==1.11.0
azure-storage-blob==12.7.1
backcall==0.2.0
base58==2.1.0
binaryornot==0.4.4
bleach==3.2.3
blinker==1.4
boto3==1.17.2
botocore==1.20.2
cachetools==4.2.1
category-encoders==2.2.2
certifi==2020.12.5
cffi==1.14.4
chardet==3.0.4
click==7.1.2
cloudpickle==1.6.0
colorama==0.4.4
commonmark==0.9.1
confuse==1.4.0
cookiecutter==1.7.2
cryptography==3.3.1
cycler==0.10.0
dask==2021.2.0
databricks-cli==0.14.1
decorator==4.4.2
defusedxml==0.6.0
distributed==2021.2.0
docker==4.4.2
docutils==0.16
entrypoints==0.3
Faker==6.0.0
fastapi==0.63.0
featuretools==0.23.1
Flask==1.1.2
fsspec==0.8.5
gitdb==4.0.5
GitPython==3.1.12
great-expectations==0.13.8
gunicorn==20.0.4
HeapDict==1.0.1
htmlmin==0.1.12
hypothesis==6.3.4
idna==2.10
ImageHash==4.2.0
importlib-metadata==2.1.1
iniconfig==1.1.1
ipykernel==5.4.3
ipython==7.19.0
ipython-genutils==0.2.0
ipywidgets==7.6.3
isodate==0.6.0
itsdangerous==1.1.0
jedi==0.18.0
Jinja2==2.11.2
jinja2-time==0.2.0
jinjasql==0.1.8
jmespath==0.10.0
joblib==1.0.0
jsonpatch==1.28
jsonpointer==2.0
jsonschema==3.2.0
jupyter==1.0.0
jupyter-client==6.1.11
jupyter-console==6.2.0
jupyter-core==4.7.0
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.0
kiwisolver==1.3.1
lightgbm==3.1.1
locket==0.2.1
loky==2.9.0
Mako==1.1.4
MarkupSafe==1.1.1
matplotlib==3.3.3
missingno==0.4.2
mistune==0.8.4
mlflow==1.13.1
mock==4.0.3
msgpack==1.0.2
msrest==0.6.21
mypy-extensions==0.4.3
nbclient==0.5.1
nbconvert==6.0.7
nbformat==5.1.2
nest-asyncio==1.5.1
networkx==2.5
nltk==3.5
notebook==6.2.0
numpy==1.19.5
oauthlib==3.1.0
opt-einsum==3.3.0
packaging==20.8
pandas==1.2.1
pandas-profiling==2.11.0
pandera==0.6.2
pandocfilters==1.4.3
parso==0.8.1
partd==1.1.0
patsy==0.5.1
pexpect==4.8.0
phik==0.11.2
pickleshare==0.7.5
Pillow==8.1.0
pluggy==0.13.1
poyo==0.5.0
prometheus-client==0.9.0
prometheus-flask-exporter==0.18.1
prompt-toolkit==3.0.14
protobuf==3.14.0
psutil==5.8.0
psycopg2-binary==2.8.6
ptyprocess==0.7.0
py==1.10.0
pycparser==2.20
pydantic==1.7.3
pydeck==0.5.0
Pygments==2.7.4
pyOpenSSL==20.0.1
pyparsing==2.4.7
PyPika==0.47.4
pyro-api==0.1.2
pyro-ppl==1.5.2
pyrsistent==0.17.3
pytest==6.2.2
python-dateutil==2.8.1
python-dotenv==0.15.0
python-editor==1.0.4
python-slugify==4.0.1
pytz==2020.5
PyWavelets==1.1.1
PyYAML==5.4.1
pyzmq==21.0.2
qtconsole==5.0.2
QtPy==1.9.0
querystring-parser==1.2.4
regex==2020.11.13
requests==2.25.1
requests-oauthlib==1.3.0
rich==9.11.0
rpy2==3.4.2
ruamel.yaml==0.16.12
s3transfer==0.3.4
scikit-learn==0.24.1
scipy==1.6.0
seaborn==0.11.1
Send2Trash==1.5.0
shellingham==1.4.0
six==1.15.0
smart-open==4.2.0
smmap==3.0.5
sortedcontainers==2.3.0
SQLAlchemy==1.3.23
sqlparse==0.4.1
starlette==0.13.6
statsmodels==0.12.2
streamlit==0.77.0
tabulate==0.8.7
tangled-up-in-unicode==0.0.6
tblib==1.7.0
termcolor==1.1.0
terminado==0.9.2
testpath==0.4.4
text-unidecode==1.3
threadpoolctl==2.1.0
toml==0.10.2
toolz==0.11.1
torch==1.7.1
tornado==6.1
tqdm==4.56.0
traitlets==5.0.5
typer==0.3.2
typer-cli==0.0.11
typing-extensions==3.7.4.3
typing-inspect==0.6.0
tzlocal==2.1
urllib3==1.25.11
validators==0.18.2
visions==0.6.0
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==0.57.0
Werkzeug==1.0.1
widgetsnbextension==3.5.1
wrapt==1.12.1
zict==2.0.0
zipp==3.4.0
```
</p></summary></details>




Discussion:

Resolving patch:
diff --git a/src/pandas_profiling/model/expectation_algorithms.py b/src/pandas_profiling/model/expectation_algorithms.py
--- a/src/pandas_profiling/model/expectation_algorithms.py
+++ b/src/pandas_profiling/model/expectation_algorithms.py
@@ -69,7 +69,10 @@ def path_expectations(name, summary, batch, *args):
 def datetime_expectations(name, summary, batch, *args):
     if any(k in summary for k in ["min", "max"]):
         batch.expect_column_values_to_be_between(
-            name, min_value=summary.get("min"), max_value=summary.get("max")
+            name,
+            min_value=summary.get("min"),
+            max_value=summary.get("max"),
+            parse_strings_as_datetimes=True,
         )
 
     return name, summary, batch


Test patch: