from __future__ import absolute_import, division, print_function

from datashape import discover
import datashape

import pandas as pd

@discover.register(pd.DataFrame)
def discover_dataframe(df):
    obj = datashape.coretypes.object_
    names = list(df.columns)
    dtypes = list(map(datashape.CType.from_numpy_dtype, df.dtypes))
    dtypes = [datashape.string if dt == obj else dt for dt in dtypes]
    schema = datashape.Record(list(zip(names, dtypes)))
    return len(df) * schema


@discover.register(pd.Series)
def discover_series(s):
    return len(s) * datashape.CType.from_numpy_dtype(s.dtype)

@@ -597,8 +597,722 @@
 .dtype)%0A
+%0A%0Adef coerce_datetimes(df):%0A    %22%22%22 Make object columns into datetimes if possible%0A%0A    Warning: this operates inplace.%0A%0A    Example%0A    -------%0A%0A    %3E%3E%3E df = pd.DataFrame(%7B'dt': %5B'2014-01-01'%5D, 'name': %5B'Alice'%5D%7D)%0A    %3E%3E%3E df.dtypes  # note that these are strings/object%0A    dt      object%0A    name    object%0A    dtype: object%0A%0A    %3E%3E%3E df2 = coerce_datetimes(df)%0A    %3E%3E%3E df2%0A              dt   name%0A    0 2014-01-01  Alice%0A%0A    %3E%3E%3E df2.dtypes  # note that only the datetime-looking-one was transformed%0A    dt      datetime64%5Bns%5D%0A    name            object%0A    dtype: object%0A    %22%22%22%0A    df2 = df.select_dtypes(include=%5B'object'%5D).apply(pd.to_datetime)%0A    for c in df2.columns:%0A        df%5Bc%5D = df2%5Bc%5D%0A    return df%0A

pandas coerce datetimes