Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datatime parsed by from_dict and from_dicts are different #4216

Closed
Tatametheus opened this issue Aug 2, 2022 · 0 comments · Fixed by #4221
Closed

Datatime parsed by from_dict and from_dicts are different #4216

Tatametheus opened this issue Aug 2, 2022 · 0 comments · Fixed by #4221
Labels
bug Something isn't working

Comments

@Tatametheus
Copy link

What language are you using?

Python

Have you tried latest version of polars?

yes

If the problem was resolved, please update polars. :)

What version of polars are you using?

polars 0.13.59 pypi_0 pypi

What operating system are you using polars on?

Windows 11 Conda

What language version are you using

python 3.9.13

Describe your bug.

list of dicts

[{'symbol': 'SHSE.600000', 'open': 7.23, 'high': 7.25, 'low': 7.23, 'close': 7.25, 'eob': datetime.datetime(2022, 8, 1, 14, 56, tzinfo=tzfile('PRC')), 'amount': 417774.0, 'volume': 57695}, {'symbol': 'SHSE.600000', 'open': 7.25, 'high': 7.25, 'low': 7.23, 'close': 7.23, 'eob': datetime.datetime(2022, 8, 1, 14, 57, tzinfo=tzfile('PRC')), 'amount': 818076.0, 'volume': 113005}, {'symbol': 'SHSE.600000', 'open': 7.23, 'high': 7.23, 'low': 7.23, 'close': 7.23, 'eob': datetime.datetime(2022, 8, 1, 15, 0, tzinfo=tzfile('PRC')), 'amount': 6668280.0, 'volume': 922307}]

one dict

{'symbol': 'SHSE.600000', 'eob': datetime.datetime(2022, 8, 2, 9, 31, tzinfo=tzfile('PRC')), 'bob': datetime.datetime(2022, 8, 2, 9, 30, tzinfo=tzfile('PRC')), 'open': 7.22, 'close': 7.2, 'high': 7.22, 'low': 7.19, 'volume': 772000, 'amount': 5563492.0, 'pre_close': 0.0, 'position': 0, 'frequency': '60s', 'receive_local_time': 1659425273.225259}

using pl.from_dicts(data)
the datatime(PRC) is pased to datatime[ms]

┌─────────────┬──────┬──────┬──────┬───────┬─────────────────────┬───────────┬────────┐
│ symbol      ┆ open ┆ high ┆ low  ┆ close ┆ eob                 ┆ amount    ┆ volume │
│ ---         ┆ ---  ┆ ---  ┆ ---  ┆ ---   ┆ ---                 ┆ ---       ┆ ---    │
│ str         ┆ f64  ┆ f64  ┆ f64  ┆ f64   ┆ datetime[ms]        ┆ f64       ┆ i64    │
╞═════════════╪══════╪══════╪══════╪═══════╪═════════════════════╪═══════════╪════════╡
│ SHSE.600000 ┆ 7.23 ┆ 7.25 ┆ 7.23 ┆ 7.25  ┆ 2022-08-01 14:56:00 ┆ 417774.0  ┆ 57695  │
├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ SHSE.600000 ┆ 7.25 ┆ 7.25 ┆ 7.23 ┆ 7.23  ┆ 2022-08-01 14:57:00 ┆ 818076.0  ┆ 113005 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ SHSE.600000 ┆ 7.23 ┆ 7.23 ┆ 7.23 ┆ 7.23  ┆ 2022-08-01 15:00:00 ┆ 6.66828e6 ┆ 922307 │
└─────────────┴──────┴──────┴──────┴───────┴─────────────────────┴───────────┴────────┘

using pl.from_dict(data)
the datatime(PRC) is parsed to datetime[μs, PRC]

┌─────────────┬──────┬──────┬──────┬───────┬─────────────────────────┬────────────┬────────┐
│ symbol      ┆ open ┆ high ┆ low  ┆ close ┆ eob                     ┆ amount     ┆ volume │
│ ---         ┆ ---  ┆ ---  ┆ ---  ┆ ---   ┆ ---                     ┆ ---        ┆ ---    │
│ str         ┆ f64  ┆ f64  ┆ f64  ┆ f64   ┆ datetime[μs, PRC]       ┆ f64        ┆ i64    │
╞═════════════╪══════╪══════╪══════╪═══════╪═════════════════════════╪════════════╪════════╡
│ SHSE.600000 ┆ 7.22 ┆ 7.22 ┆ 7.19 ┆ 7.2   ┆ 2022-08-02 01:31:00 CST ┆ 5.563492e6 ┆ 772000 │

What are the steps to reproduce the behavior?

from datetime import datetime
import pytz
import polars as pl
tz  = pytz.timezone("PRC")
dt = datetime(2020,8,1,12,0,0,tzinfo=tz)
from_dict = pl.from_dict(
  {
    "dt":[dt]
  }  
)
from_dicts = pl.from_dicts([{
    "dt":dt
}])
print("------from_dict-----")
print(from_dict)
print("------from_dicts-----")
print(from_dicts)
------from_dict-----
shape: (1, 1)
┌─────────────────────────┐
│ dt                      │
│ ---                     │
│ datetime[μs, PRC]       │
╞═════════════════════════╡
│ 2020-08-01 03:54:00 CST │
└─────────────────────────┘
------from_dicts-----
shape: (1, 1)
┌─────────────────────┐
│ dt                  │
│ ---                 │
│ datetime[ms]        │
╞═════════════════════╡
│ 2020-08-01 12:00:00 │
└─────────────────────┘
@Tatametheus Tatametheus added the bug Something isn't working label Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant