Polars read_json не может проанализировать схему типа датыPython

Программы на Python
Anonymous
 Polars read_json не может проанализировать схему типа даты

Сообщение Anonymous »

Я хочу прочитать в кадре данных Polars строку json, содержащую даты в стандартном iso-формате "гггг-мм-дд".
Когда я пытаюсь прочитать строку и установить dtype столбца даты с помощью схемы или Schema_override, это приводит только к значениям NULL.
MRE

Код: Выделить всё

from datetime import datetime, timedelta
from io import StringIO

import polars as pl

# Generate a list of dates
start_date = datetime.today()
dates = [start_date + timedelta(days=i) for i in range(100)]
date_strings = [date.strftime("%Y-%m-%d") for date in dates]

# Create a Polars DataFrame
df = pl.DataFrame({"dates": date_strings})

df_reread = pl.read_json(
StringIO(df.write_json()),
schema_overrides={"dates": pl.Date},
)
вывод на печать (df_reread)
Ошибка

Код: Выделить всё

shape: (100, 1)
┌───────┐
│ dates │
│ ---   │
│ date  │
╞═══════╡
│ null  │
│ null  │
│ null  │
│ null  │
│ null  │
│ …     │
│ null  │
│ null  │
│ null  │
│ null  │
│ null  │
└───────┘
Вопрос
Можно ли как-нибудь правильно прочитать тип даты из строки json?

Подробнее здесь: https://stackoverflow.com/questions/790 ... ype-schema

Вернуться в «Python»