Skip to content

Commit 650a97e

Browse files
author
miranov25
committed
Phase 13.12.DF: profile() enhancements - return_data, min_entries, group_by_bins, sort_groups
Features: - F1: return_data=True exports profile statistics as DataFrame - F2: min_entries=3 suppresses low-statistics bins from plot (AD-1) - F3: group_by_bins/group_by_quantiles auto-bins float columns - F4: sort_groups=True sorts legend numerically/alphabetically Architect decisions: AD-1 (min_entries default), AD-2 (profile only), AD-3 (interval label format) 15 new tests, 311 existing tests pass.
1 parent e42a91d commit 650a97e

3 files changed

Lines changed: 600 additions & 36 deletions

File tree

UTILS/dfextensions/dfdraw/drawer.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,12 @@ def profile(
693693
sharex: bool = True,
694694
sharey: bool = True,
695695
top_k: Optional[int] = None,
696+
# Phase 13.12.DF: New parameters
697+
return_data: bool = False,
698+
min_entries: int = 3,
699+
group_by_bins: Optional[int] = None,
700+
group_by_quantiles: Optional[int] = None,
701+
sort_groups: bool = True,
696702
**kwargs
697703
) -> DrawResult:
698704
"""
@@ -734,13 +740,33 @@ def profile(
734740
Share y-axis in facet mode.
735741
top_k : int, optional
736742
Show only top K groups.
743+
return_data : bool, default False
744+
If True, include 'profile_data' DataFrame in stats_dict.
745+
Phase 13.12.DF F1.
746+
min_entries : int, default 3
747+
Minimum entries per bin to be plotted. Bins with fewer entries
748+
are excluded from the plot but included in profile_data.
749+
AD-1: default=3 for stable error bars. Phase 13.12.DF F2.
750+
group_by_bins : int, optional
751+
Number of equal-width bins for float group_by column.
752+
Mutually exclusive with group_by_quantiles. Phase 13.12.DF F3.
753+
group_by_quantiles : int, optional
754+
Number of equal-count quantile bins for float group_by column.
755+
Mutually exclusive with group_by_bins. Phase 13.12.DF F3.
756+
sort_groups : bool, default True
757+
If True, sort groups numerically/alphabetically in legend.
758+
Phase 13.12.DF F4.
737759
**kwargs
738760
Additional arguments.
739761
740762
Returns
741763
-------
742764
tuple
743765
(fig, ax, stats_dict)
766+
767+
If return_data=True, stats_dict['profile_data'] contains DataFrame
768+
with columns: x_center, x_low, x_high, y_mean, y_std, y_sem, count,
769+
and 'group' if group_by is used.
744770
"""
745771
from .plots.profile import draw_profile
746772

@@ -779,15 +805,25 @@ def profile(
779805
df, x_expr, y_expr, group_by,
780806
top_k=top_k, ncols=ncols, sharex=sharex, sharey=sharey,
781807
suptitle=title, bins=bins, x_range=range, error=error,
782-
stats=stats, xlabel=xlabel, ylabel=ylabel, **kwargs
808+
stats=stats, xlabel=xlabel, ylabel=ylabel,
809+
# Phase 13.12.DF: pass new parameters
810+
return_data=return_data, min_entries=min_entries,
811+
group_by_bins=group_by_bins, group_by_quantiles=group_by_quantiles,
812+
sort_groups=sort_groups,
813+
**kwargs
783814
)
784815
else:
785816
# Standard mode (single plot or overlay)
786817
fig, ax, stats_dict = draw_profile(
787818
df, x_expr, y_expr,
788819
ax=ax, bins=bins, x_range=range, error=error,
789820
stats=stats, title=title, xlabel=xlabel, ylabel=ylabel,
790-
group_by=group_by, top_k=top_k, **kwargs
821+
group_by=group_by, top_k=top_k,
822+
# Phase 13.12.DF: pass new parameters
823+
return_data=return_data, min_entries=min_entries,
824+
group_by_bins=group_by_bins, group_by_quantiles=group_by_quantiles,
825+
sort_groups=sort_groups,
826+
**kwargs
791827
)
792828
axes = ax
793829

0 commit comments

Comments
 (0)