|
15 | 15 | ) |
16 | 16 |
|
17 | 17 | import narwhals.stable.v2 as nw |
18 | | -from narwhals.dependencies import is_narwhals_lazyframe |
19 | 18 | from narwhals.typing import IntoDataFrame, IntoLazyFrame |
20 | 19 |
|
21 | 20 | from marimo import _loggers |
|
55 | 54 | RowOrientedData = list[dict[str, Any]] |
56 | 55 | ColumnOrientedData = dict[str, list[Any]] |
57 | 56 |
|
58 | | -ChartDataType = Union[IntoDataFrame, RowOrientedData, ColumnOrientedData] |
| 57 | +ChartDataType = Union[ |
| 58 | + IntoDataFrame, IntoLazyFrame, RowOrientedData, ColumnOrientedData |
| 59 | +] |
59 | 60 |
|
60 | 61 | # Union of all possible chart types |
61 | 62 | AltairChartType: TypeAlias = "altair.vegalite.v5.api.ChartType" |
@@ -98,12 +99,8 @@ def _using_vegafusion() -> bool: |
98 | 99 |
|
99 | 100 | def _filter_dataframe( |
100 | 101 | native_df: Union[IntoDataFrame, IntoLazyFrame], selection: ChartSelection |
101 | | -) -> IntoDataFrame: |
102 | | - df = nw.from_native(native_df).lazy() |
103 | | - if is_narwhals_lazyframe(df): |
104 | | - raise ValueError( |
105 | | - "Lazyframes are not supported for filtering. Run `df.collect()` before filtering." |
106 | | - ) |
| 102 | +) -> Union[IntoDataFrame, IntoLazyFrame]: |
| 103 | + df = nw.from_native(native_df) |
107 | 104 | if not isinstance(selection, dict): |
108 | 105 | raise TypeError("Input 'selection' must be a dictionary") |
109 | 106 |
|
@@ -187,14 +184,9 @@ def _coerce_value(value: Any, dtype: Any) -> Any: |
187 | 184 | if nw.Datetime == dtype and isinstance(dtype, nw.Datetime): |
188 | 185 | if isinstance(value, str): |
189 | 186 | res = datetime.datetime.fromisoformat(value) |
190 | | - # If dtype has no timezone, shift by local timezone offset |
191 | | - if dtype.time_zone is None: |
192 | | - local_tz = datetime.datetime.now().astimezone().tzinfo |
193 | | - LOGGER.warning( |
194 | | - f"Datetime was given with a timezone when not expected. " |
195 | | - f"Shifting by local timezone offset {local_tz}." |
196 | | - ) |
197 | | - return res.astimezone(local_tz).replace(tzinfo=None) |
| 187 | + # If dtype has no timezone, but value has timezone, remove timezone without shifting |
| 188 | + if dtype.time_zone is None and res.tzinfo is not None: |
| 189 | + return res.replace(tzinfo=None) |
198 | 190 | return res |
199 | 191 |
|
200 | 192 | # Value is milliseconds since epoch |
|
0 commit comments