Skip to content

Commit 45a4d5e

Browse files
committed
Support latest dagster-polars dependencies
1 parent c7652ee commit 45a4d5e

4 files changed

Lines changed: 62 additions & 20 deletions

File tree

libraries/dagster-polars/dagster_polars/io_managers/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ def setup_for_execution(self, context: InitResourceContext) -> None:
8585
else UPath(check.not_none(context.instance).storage_directory())
8686
)
8787

88+
@property
89+
def storage_options(self) -> dict[str, Any]:
90+
"""Return UPath storage options across universal-pathlib versions.
91+
92+
Dagster's ``UPathIOManager`` currently reads the private ``_kwargs``
93+
attribute, which was removed in universal-pathlib 0.3. Prefer the
94+
public ``storage_options`` attribute when present and fall back to the
95+
legacy private attribute for universal-pathlib 0.2.
96+
"""
97+
if hasattr(self._base_path, "storage_options"):
98+
return dict(self._base_path.storage_options or {})
99+
if hasattr(self._base_path, "_kwargs"):
100+
return self._base_path._kwargs.copy() # noqa: SLF001
101+
return {}
102+
88103
@abstractmethod
89104
def write_df_to_path(
90105
self,

libraries/dagster-polars/dagster_polars/io_managers/delta.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
from typing import TYPE_CHECKING, Any, ClassVar, Optional
66

77
import polars as pl
8-
from dagster import InputContext, MetadataValue, MultiPartitionKey, OutputContext
8+
from dagster import (
9+
InputContext,
10+
MetadataValue,
11+
MultiPartitionKey,
12+
MultiPartitionsDefinition,
13+
OutputContext,
14+
TimeWindowPartitionsDefinition,
15+
)
916
from dagster._core.errors import DagsterInvariantViolationError
1017
from dagster._core.storage.upath_io_manager import is_dict_type
1118
from packaging.version import parse as parse_version
@@ -484,7 +491,18 @@ def get_predicate(
484491
f"Invalid context type: {type(context)}"
485492
)
486493

487-
def key_to_predicate(key):
494+
def key_to_predicate(key: str, dim: str | None = None) -> str:
495+
partitions_def = context.asset_partitions_def
496+
if dim is not None and isinstance(
497+
partitions_def, MultiPartitionsDefinition
498+
):
499+
dim_partitions_def = partitions_def.get_partitions_def_for_dimension(
500+
dim
501+
)
502+
if isinstance(dim_partitions_def, TimeWindowPartitionsDefinition):
503+
return f"DATE '{key}'"
504+
elif isinstance(partitions_def, TimeWindowPartitionsDefinition):
505+
return f"DATE '{key}'"
488506
return f"'{key}'"
489507

490508
if partition_by is None or not context.has_asset_partitions:
@@ -502,7 +520,7 @@ def key_to_predicate(key):
502520

503521
predicate = " AND ".join(
504522
[
505-
f"{partition_by[dim]} in ({', '.join(map(key_to_predicate, keys))})"
523+
f"{partition_by[dim]} in ({', '.join(key_to_predicate(key, dim) for key in keys)})"
506524
for dim, keys in all_keys_by_dim.items()
507525
]
508526
)
@@ -514,7 +532,7 @@ def key_to_predicate(key):
514532
)
515533

516534
if len(context.asset_partition_keys) == 1:
517-
predicate = f"{partition_by} = '{context.asset_partition_keys[0]}'"
535+
predicate = f"{partition_by} = {key_to_predicate(context.asset_partition_keys[0])}"
518536
else:
519537
predicate = f"{partition_by} in ({', '.join(map(key_to_predicate, context.asset_partition_keys))})"
520538

libraries/dagster-polars/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ dependencies = [
1818
"polars>=1.0.0",
1919
"pyarrow>=8.0.0",
2020
"typing-extensions>=4.7.0",
21-
"universal-pathlib>=0.1.4,<0.3",
21+
"universal-pathlib>=0.1.4",
2222
]
2323
dynamic = ["version"]
2424

2525
[project.optional-dependencies]
26-
deltalake = ["deltalake>=0.25.0,<1.2"]
26+
deltalake = ["deltalake>=0.25.0"]
2727
gcp = ["dagster-gcp>=0.19.5"]
2828
patito = [
2929
"patito>=0.8.3",

libraries/dagster-polars/uv.lock

Lines changed: 23 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)