Skip to content

Commit dd8b74e

Browse files
author
Saurabh Badenkal
committed
Fix typing annotation, optimize weighted_pipeline aggregation, clarify select comment
- __init__.py: use typing.List[str] instead of list[str] for broader compat - datascience: precompute weighted_value column before groupby (faster, cleaner) - prodev: clarify that SDK auto-lowercases select values
1 parent 8630e5a commit dd8b74e

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

examples/advanced/datascience_risk_assessment.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,20 @@ def step2_analyze(accounts, cases, opportunities):
343343

344344
# -- Opportunity pipeline analysis per account --
345345
if not opportunities.empty and "_parentaccountid_value" in opportunities.columns:
346+
# Precompute weighted value to avoid closure-based aggregation
347+
opportunities = opportunities.copy()
348+
opportunities["_weighted_value"] = (
349+
pd.to_numeric(opportunities["estimatedvalue"], errors="coerce").fillna(0)
350+
* pd.to_numeric(opportunities["closeprobability"], errors="coerce").fillna(0)
351+
/ 100
352+
)
346353
opp_stats = (
347354
opportunities.groupby("_parentaccountid_value")
348355
.agg(
349356
total_opportunities=("opportunityid", "count"),
350357
pipeline_value=("estimatedvalue", "sum"),
351358
avg_close_probability=("closeprobability", "mean"),
352-
weighted_pipeline=(
353-
"estimatedvalue",
354-
lambda x: (x * opportunities.loc[x.index, "closeprobability"] / 100).sum(),
355-
),
359+
weighted_pipeline=("_weighted_value", "sum"),
356360
)
357361
.reset_index()
358362
.rename(columns={"_parentaccountid_value": "accountid"})

examples/advanced/prodev_quick_start.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ def step4_query_and_analyze(client, customer_ids, primary_name_col):
384384
print("-" * 60)
385385

386386
# Query all projects as a DataFrame
387-
# Note: select uses logical names (lowercase). The SDK lowercases automatically.
387+
# Note: The SDK lowercases $select values automatically, so schema-name
388+
# casing (e.g., new_DemoProject_Budget) works -- it becomes the logical name.
388389
name_attr = primary_name_col
389390
projects = client.dataframe.get(
390391
TABLE_PROJECT,

src/PowerPlatform/Dataverse/operations/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
SDK operations into logical groups: records, query, and tables.
99
"""
1010

11-
__all__: list[str] = []
11+
from typing import List
12+
13+
__all__: List[str] = []

0 commit comments

Comments
 (0)