Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] Fix min_max_scale docstrings rendering #1123

Merged
merged 8 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
- [ENH] New decorator `deprecated_kwargs` for breaking API. #1103 @Zeroto521
- [ENH] Extend select_columns to support non-string columns. Also allow selection on MultiIndex columns via level parameter. #1105 @samukweku
- [ENH] Performance improvement for groupby_topk. #1093 @samukweku
- [EHN] `min_max_scale` drop `old_min` and `old_max` to fit sklearn's method API. Issue #1068 @Zeroto521
- [EHN] Add `jointly` option for `min_max_scale` support to transform each column values or entire values. Default transform each column, similar behavior to `sklearn.preprocessing.MinMaxScaler`. Issue #1067 @Zeroto521
- [ENH] `min_max_scale` drop `old_min` and `old_max` to fit sklearn's method API. Issue #1068 @Zeroto521
- [ENH] Add `jointly` option for `min_max_scale` support to transform each column values or entire values. Default transform each column, similar behavior to `sklearn.preprocessing.MinMaxScaler`. (Issue #1067, PR #1112, PR #1123) @Zeroto521

## [v0.23.1] - 2022-05-03

Expand Down Expand Up @@ -82,7 +82,7 @@
- [DOC] Updated various documentation sources to reflect pyjanitor-dev ownership. @loganthomas
- [INF] Fix `isort` automatic checks. Issue #845. @loganthomas
- [ENH] `complete` function now uses variable args (\*args) - @samukweku
- [EHN] Set `expand_column`'s `sep` default is `"|"`, same to `pandas.Series.str.get_dummies`. Issue #876. @Zeroto521
- [ENH] Set `expand_column`'s `sep` default is `"|"`, same to `pandas.Series.str.get_dummies`. Issue #876. @Zeroto521
- [ENH] Deprecate `limit` from fill_direction. fill_direction now uses kwargs. @samukweku
- [ENH] Added `conditional_join` function that supports joins on non-equi operators. @samukweku
- [INF] Speed up pytest via `-n` (pytest-xdist) option. Issue #881. @Zeroto521
Expand Down
22 changes: 12 additions & 10 deletions janitor/functions/min_max_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def min_max_scale(
1 to 14. Hence, 3 gets scaled not to 0 but approx. 0.15 instead, while 10
gets scaled to approx. 0.69 instead.

!!! summary "Version Changed"

- 0.24.0
- Deleted `old_min`, `old_max`, `new_min`, and `new_max` options.
- Added `feature_range`, and `jointly` options.

:param df: A pandas DataFrame.
:param feature_range: (optional) Desired range of transformed data.
:param column_name: (optional) The column on which to perform scaling.
Expand All @@ -105,10 +111,6 @@ def min_max_scale(
:raises ValueError: if the length of `feature_range` isn't equal to two.
:raises ValueError: if the element of `feature_range` isn't number type.
:raises ValueError: if `feature_range[1]` <= `feature_range[0]`.

Changed in version 0.24.0: Deleted "old_min", "old_max", "new_min", and
"new_max" options.
Changed in version 0.24.0: Added "feature_range", and "jointly" options.
"""

if not (
Expand All @@ -125,24 +127,24 @@ def min_max_scale(
if column_name is not None:
df = df.copy() # Avoid to change the original DataFrame.

old_feature_range = df[column_name].pipe(min_max_value, jointly)
old_feature_range = df[column_name].pipe(_min_max_value, jointly)
df[column_name] = df[column_name].pipe(
apply_min_max,
_apply_min_max,
*old_feature_range,
*feature_range,
)
else:
old_feature_range = df.pipe(min_max_value, jointly)
old_feature_range = df.pipe(_min_max_value, jointly)
df = df.pipe(
apply_min_max,
_apply_min_max,
*old_feature_range,
*feature_range,
)

return df


def min_max_value(df: pd.DataFrame, jointly: bool) -> tuple:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions/init.py only imports min_max_scale.
But the docstring of inner methods would be rendered by mkdocs.
This behavior is quite different to sphinx.

def _min_max_value(df: pd.DataFrame, jointly: bool) -> tuple:
"""
Return the minimum and maximum of DataFrame.

Expand All @@ -162,7 +164,7 @@ def min_max_value(df: pd.DataFrame, jointly: bool) -> tuple:
return mmin, mmax


def apply_min_max(
def _apply_min_max(
df: pd.DataFrame,
old_min: int | float | pd.Series,
old_max: int | float | pd.Series,
Expand Down