Skip to content

feat: improve excel date datatype in context.preview api #349

@leavesster

Description

@leavesster

When pandas load data from excel, some date columns will load as datetime object.

Excel content:

date count
2019/1/1 1
2019/1/2 1
2019/1/3 1
2019/1/4 1
2019/1/5 1
2019/1/6 1
pip install pandas openpyxl
import pandas
# from json import dumps

def main():
    df = pandas.read_excel('date.xlsx')
    print(df)
    print(df.dtypes)
    # d = dumps(df.to_dict(orient='split')) # will crash and report 'TypeError: Object of type Timestamp is not JSON serializable'

if __name__ == "__main__":
    main()

Currently context api use to_json instead of to_dict to avoid this error.

to_json will transform date to epoch milliseconds(default) or ISO8601(iso option) format. The default ISO 8601 format is 2019-01-02T00:00:00.000.


Target:

  • It should be better use local timezone or what we see in Excel(the actually value is float).
  • Add datetime test case

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions