[MNT] Deprecate LogCpTransformer in favour of LogTransformer with C parameter#970
[MNT] Deprecate LogCpTransformer in favour of LogTransformer with C parameter#970adityaanikam wants to merge 12 commits into
Conversation
solegalli
left a comment
There was a problem hiding this comment.
This is looking really good! Thank you so much for the first draft.
I left a few comments, mostly to add future warnings about the deprecation, and to add the tests for C in the logtransform tests.
The last bit that needs updating to have this one ready is the user guide. Inside the docs folder, useguide/transformers, we need to add the demo of the use of C to Logtransfor.rst. You could probably re-adapt the examples that we have for logcp.
Thanks a lot!
| The constant C to add to the variable before the logarithm, i.e., log(x + C). | ||
|
|
||
| - If 0 (the default), no constant is added and the variable must be | ||
| strictly positive, matching the transformer's original behavior. |
There was a problem hiding this comment.
| strictly positive, matching the transformer's original behavior. | |
| strictly positive. |
| The LogTransformer() only works with positive values. If the variable | ||
| contains a zero or a negative value the transformer will return an error. | ||
| By default, C=0, so LogTransformer() only works with positive values and | ||
| behaves exactly as it always has: if a variable contains a zero or a negative |
There was a problem hiding this comment.
| behaves exactly as it always has: if a variable contains a zero or a negative | |
| If a variable contains a zero or a negative |
|
|
||
| The LogTransformer() only works with positive values. If the variable | ||
| contains a zero or a negative value the transformer will return an error. | ||
| By default, C=0, so LogTransformer() only works with positive values and |
There was a problem hiding this comment.
| By default, C=0, so LogTransformer() only works with positive values and | |
| By default, C=0, so LogTransformer() only works with positive values. |
| contains a zero or a negative value the transformer will return an error. | ||
| By default, C=0, so LogTransformer() only works with positive values and | ||
| behaves exactly as it always has: if a variable contains a zero or a negative | ||
| value, the transformer raises an error. |
There was a problem hiding this comment.
Could we add a note saying that C will be changed from 0 to "auto" in version 2.1.0? I think this is the easiest way to avoid the error on negative values that we were discussing earlier.
| {variables_} | ||
|
|
||
| C_: | ||
| The constant C added to each variable. Equal to C, unless C = "auto", in |
There was a problem hiding this comment.
| The constant C added to each variable. Equal to C, unless C = "auto", in | |
| The constant C added to each variable. Equal to `C`, unless `C = "auto"`, in |
| can be applied on the selected variables, i.e., it checks that the variables | ||
| are positive. | ||
| Selects the numerical variables and, when C=0 (the default), determines | ||
| whether the logarithm can be applied on the selected variables, i.e., it |
There was a problem hiding this comment.
I think we should remove lines 157-159.
| The constant C to add to each variable. If C = "auto" a dictionary with | ||
| C = abs(min(variable)) + 1. For strictly positive variables, C = 0. | ||
| .. note:: | ||
| `LogCpTransformer` is being consolidated into `LogTransformer`. New |
There was a problem hiding this comment.
Could we add the version changes and future deprecations in this note? Something like:
LogCpTransformer is consolidated into LogTransformer in version 2.0.0 and will be deprecated in version 2.1.0. New code....
| class LogCpTransformer(BaseNumericalTransformer, FitFromDictMixin): | ||
| class LogCpTransformer(LogTransformer): | ||
| """ | ||
| LogCpTransformer() applies the transformation log(x + C), where x is the |
There was a problem hiding this comment.
| LogCpTransformer() applies the transformation log(x + C), where x is the | |
| #TODO: remove in version 2.1.0 | |
| LogCpTransformer() applies the transformation log(x + C), where x is the |
| super().__init__( | ||
| variables=variables, return_empty=return_empty, base=base, C=C | ||
| ) | ||
|
|
There was a problem hiding this comment.
Could we add a future warning in the init saying that LogCP... was deprecated in favour of LogTransformer in version 2.0.0 and will be removed in version 2.1.0. Use LogTransformer() instead? So every time someone uses this class, they are alerted that it will disappear in the next version?
| # test transform output | ||
| pd.testing.assert_frame_equal(X, df_vartypes) | ||
|
|
||
|
|
There was a problem hiding this comment.
We should bring the tests for C, from test_logcp to this file as well, so we know it works as intended.
- Emit a FutureWarning on LogCpTransformer instantiation, announcing its removal in version 2.1.0 in favour of LogTransformer(C=auto). - Align the LogCpTransformer docstring note with that warning: it is deprecated in 2.0.0 and removed in 2.1.0, not deprecated in 2.1.0. - Explain why `variables` is ignored when C is a dictionary (the variables are taken from the dictionary keys) instead of restating that C accepts dictionaries, which the parameter list above already documents. - Mark the pending removal with a TODO above the class statement so it stays a developer note rather than rendered documentation text. - Note in LogTransformer's docstring that C will default to auto in 2.1.0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Port the C-parameter tests from test_logcp_transformer.py to test_log_transformer.py, covering parameter validation, C=auto/dict/int at fit time, the transform-time positivity check, both logarithm bases and inverse_transform. Uses a `df_c` fixture to avoid colliding with the existing conftest fixtures. Document the new parameter in the user guide: replace the note stating that non-positive values always raise and pointing to the now-deprecated LogCpTransformer, and add a section demonstrating C=auto on the diabetes dataset. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Hi @solegalli, just wanted to flag something separate from the code review. CI has failed in the same way on three different runs of this branch now. Most recently, All 51 failures seem to come from That accounts for 48 failures in The Python version that fails also seems to vary between runs py310 on one, py314 on another, and py313 + py314 most recently so it looks more like a flaky download/CI issue than something caused by this change. I had a look at the dataset URL as well. It redirects to a presigned S3 URL with Since Happy to look into that if it would be useful, but wanted to flag it first in case you’re already aware of it or have a preferred way of handling it. |
Closes #957
Summary
Merges
LogCpTransformerintoLogTransformeras approved in the issuediscussion.
LogTransformergains aCparameter ("auto"/ int / float /dict) mirroring
LogCpTransformer's exact semantics, defaulting toC=0soexisting
LogTransformer()usage is unchanged.LogCpTransformerbecomes athin subclass defaulting to
C="auto", noted as being consolidated intoLogTransformerin favor ofLogTransformer(C=...).Backward compatibility
LogTransformer()'s behavior and error message/timing are unchanged:fit-time validation still fires exactly when
Cresolves to0(the newdefault), with the original message.
LogCpTransformer's numerical behavior andC_computation are unchanged.Things worth flagging
LogCpTransformer'sbase=error message lost its dynamicGot {base} instead.suffix — it now usesLogTransformer's originalplain message, since that's the class whose wording was promised
unchanged. Updated the corresponding test to match.
LogCpTransformergets its own_more_tags()/__sklearn_tags__()overrides resetting to the un-xfailed tags, so it doesn't silently
inherit
LogTransformer's zero-value xfail exemptions that it neverneeded (its
"auto"default always finds a valid shift).(searched — no precedent), so I kept the notice to a plain docstring
.. note::rather than inventing a formal.. deprecated::versiondirective. I also didn't touch
docs/user_guide/transformation/ LogCpTransformer.rst, which still describes it as fully independent —happy to update that in this PR or a follow-up, whichever you'd prefer.
The 0-handling-without-a-declared-constant question from the issue is left
for a follow-up, per the discussion.
Testing
pytest tests/test_transformation/— 117 passed, including a new regressiontest proving the
C=0default preserves the original fail-fast contract.