Skip to content

Commit 6e81eb1

Browse files
author
Abel Milash
committed
Polish: fix style nit, add param docstrings, walkthrough to_dataframe
1 parent c400243 commit 6e81eb1

5 files changed

Lines changed: 46 additions & 2 deletions

File tree

examples/advanced/walkthrough.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,24 @@ def _run_walkthrough(client):
347347
print(f" Page {combined_page_count}: {len(page)} records - {titles}")
348348
print(f"[OK] Combined query: {combined_record_count} records across {combined_page_count} page(s)")
349349

350+
# to_dataframe: get results as a pandas DataFrame
351+
log_call(f"client.query.builder('{table_name}').select(...).filter_eq(...).to_dataframe()")
352+
print("Querying completed records as a pandas DataFrame (to_dataframe)...")
353+
df = backoff(
354+
lambda: (
355+
client.query.builder(table_name)
356+
.select("new_title", "new_quantity")
357+
.filter_eq("new_completed", True)
358+
.to_dataframe()
359+
)
360+
)
361+
print(f"[OK] to_dataframe() returned {len(df)} rows, columns: {list(df.columns)}")
362+
if not df.empty:
363+
print(f" First row: new_title='{df.iloc[0].get('new_title')}', new_quantity={df.iloc[0].get('new_quantity')}")
364+
print(f" Sum of new_quantity: {df['new_quantity'].sum()}")
365+
else:
366+
print(" (empty DataFrame)")
367+
350368
# ============================================================================
351369
# 8. EXPAND (NAVIGATION PROPERTIES)
352370
# ============================================================================
@@ -510,7 +528,7 @@ def _run_walkthrough(client):
510528
print(" [OK] Reading records by ID and with filters")
511529
print(" [OK] Single and multiple record updates")
512530
print(" [OK] Paging through large result sets")
513-
print(" [OK] QueryBuilder fluent queries (filter_eq, filter_in, filter_between, where)")
531+
print(" [OK] QueryBuilder fluent queries (filter_eq, filter_in, filter_between, where, to_dataframe)")
514532
print(" [OK] Expand navigation properties (simple + nested ExpandOption)")
515533
print(" [OK] SQL queries")
516534
print(" [OK] Picklist label-to-value conversion")

src/PowerPlatform/Dataverse/data/_odata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,10 @@ def _get_multiple(
761761
:type expand: ``list[str]`` | ``None``
762762
:param page_size: Per-page size hint via ``Prefer: odata.maxpagesize``.
763763
:type page_size: ``int`` | ``None``
764+
:param count: If ``True``, adds ``$count=true`` to include a total record count in the response.
765+
:type count: ``bool``
766+
:param include_annotations: OData annotation pattern for the ``Prefer: odata.include-annotations`` header (e.g. ``"*"`` or ``"OData.Community.Display.V1.FormattedValue"``), or ``None``.
767+
:type include_annotations: ``str`` | ``None``
764768
765769
:return: Iterator yielding pages (each page is a ``list`` of record dicts).
766770
:rtype: ``Iterable[list[dict[str, Any]]]``

src/PowerPlatform/Dataverse/models/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def __init__(self, column: str, values: Collection[Any]) -> None:
249249

250250
def to_odata(self) -> str:
251251
# Same Collection(Edm.String) rules as _InFilter.
252-
parts = [f'"{ _format_value(v).strip("'") }"' for v in self.values]
252+
parts = [f'"{_format_value(v).strip("'")}"' for v in self.values]
253253
formatted = ",".join(parts)
254254
return (
255255
f"Microsoft.Dynamics.CRM.NotIn"

src/PowerPlatform/Dataverse/operations/dataframe.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ def get(
8888
:type expand: :class:`list` of :class:`str` or None
8989
:param page_size: Optional number of records per page for pagination.
9090
:type page_size: :class:`int` or None
91+
:param count: If ``True``, adds ``$count=true`` to include a total
92+
record count in the response.
93+
:type count: :class:`bool`
94+
:param include_annotations: OData annotation pattern for the
95+
``Prefer: odata.include-annotations`` header (e.g. ``"*"`` or
96+
``"OData.Community.Display.V1.FormattedValue"``), or ``None``.
97+
:type include_annotations: :class:`str` or None
9198
9299
:return: DataFrame containing all matching records. Returns an empty DataFrame
93100
when no records match.

src/PowerPlatform/Dataverse/operations/records.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ def get(
302302
:param page_size: Optional per-page size hint sent via
303303
``Prefer: odata.maxpagesize``.
304304
:type page_size: :class:`int` or None
305+
:param count: If ``True``, adds ``$count=true`` to include a total
306+
record count in the response.
307+
:type count: :class:`bool`
308+
:param include_annotations: OData annotation pattern for the
309+
``Prefer: odata.include-annotations`` header (e.g. ``"*"`` or
310+
``"OData.Community.Display.V1.FormattedValue"``), or ``None``.
311+
:type include_annotations: :class:`str` or None
305312
306313
:return: Generator yielding pages, where each page is a list of
307314
:class:`~PowerPlatform.Dataverse.models.record.Record` objects.
@@ -380,6 +387,14 @@ def get(
380387
:param page_size: Optional per-page size hint sent via
381388
``Prefer: odata.maxpagesize``. Only used for multi-record queries.
382389
:type page_size: :class:`int` or None
390+
:param count: If ``True``, adds ``$count=true`` to include a total
391+
record count in the response. Only used for multi-record queries.
392+
:type count: :class:`bool`
393+
:param include_annotations: OData annotation pattern for the
394+
``Prefer: odata.include-annotations`` header (e.g. ``"*"`` or
395+
``"OData.Community.Display.V1.FormattedValue"``), or ``None``.
396+
Only used for multi-record queries.
397+
:type include_annotations: :class:`str` or None
383398
384399
:return: A single record dict when ``record_id`` is provided, or a
385400
generator yielding pages (lists of record dicts) when fetching

0 commit comments

Comments
 (0)