Skip to content

Commit

Permalink
Fix #961: add datetime type detection in polars.DataFrame.
Browse files Browse the repository at this point in the history
  • Loading branch information
OLarionova-HORIS committed Mar 29, 2024
1 parent 275c4e8 commit be7ab9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion future_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
- Missing outer bar annotations when specifying `scale_x_reverse()/scale_y_reverse()` [[#1058](https://github.com/JetBrains/lets-plot/issues/1058)].
- `geom_density2d`: the doc missing some 'computed' variables [[#1062](https://github.com/JetBrains/lets-plot/issues/1062)].
- Any way to line-wrap facet labels? [[LPK-237](https://github.com/JetBrains/lets-plot-kotlin/issues/237)].
- Missing marginal gridlines.
- Missing marginal gridlines.
- DateTime is not recognised in polars.DataFrame [[#961](https://github.com/JetBrains/lets-plot/issues/961)].
10 changes: 8 additions & 2 deletions python-package/lets_plot/plot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime
from typing import Any, Tuple, Sequence, Optional, Dict

from lets_plot._type_utils import is_dict_or_dataframe
from lets_plot._type_utils import is_dict_or_dataframe, is_polars_dataframe
from lets_plot.geo_data_internals.utils import find_geo_names
from lets_plot.mapping import MappingMeta
from lets_plot.plot.core import aes
Expand Down Expand Up @@ -94,8 +94,14 @@ def __init__(self):
'parameters': value.parameters
})

data_as_dict = None
if is_dict_or_dataframe(data):
for column_name, values in data.items():
data_as_dict = data
elif is_polars_dataframe(data):
data_as_dict = data.to_dict()

if data_as_dict is not None:
for column_name, values in data_as_dict.items():
if isinstance(values, Iterable):
not_empty_series = any(True for _ in values)
if not_empty_series and all(isinstance(val, datetime) for val in values):
Expand Down
6 changes: 6 additions & 0 deletions python-package/test/plot/test_series_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def test_as_annotated_data_dataframe():
assert_series_annotations(df, expected_series_annotations)


def test_as_annotated_data_polars_dataframe():
from polars import DataFrame as plDataFrame
df = plDataFrame(data_dict)
assert_series_annotations(df, expected_series_annotations)


def test_as_annotated_data_list():
data = [dt_value]
assert {} == get_data_meta(data)
Expand Down

0 comments on commit be7ab9d

Please sign in to comment.