refactor: adds _compliant sub-package#2149
Conversation
Follow-up to #2119 (comment)
- Long-term, should probably be defined in `nw.typing` - Or just generally used in parts of each backend impl #2064 (comment)
_compliant sub-package_compliant sub-package
| CompliantSeriesOrNativeExprT_co = TypeVar( | ||
| "CompliantSeriesOrNativeExprT_co", | ||
| bound="CompliantSeries | NativeExpr", | ||
| covariant=True, | ||
| ) |
There was a problem hiding this comment.
Really want something that rolls off the tongue better than this 🤔
```log error: All protocol members must have explicitly declared types [misc] ```
|
Still managing to get more LOC (and module) reductions in (40d718f) 😉 |
- Forgot that I did that in the other PR - Important as it changes the variance of `EagerSeries` https://github.com/narwhals-dev/narwhals/blob/35cef0b1e2c892fb24aa730902b08b6994008c18/narwhals/_protocols.py#L50-L64
|
thanks - gonna review/merge tomorrow 👍 |
perfect, thanks @MarcoGorelli |
The points I'm trying to make are: - the method isn't self-explanatory from its name - `Find All References` won't show every use - This will be replaced soon - but still gathering the details on how/with what
|
Thanks for the review @MarcoGorelli - sorry that this one spiralled!
|
|
i've put up a PR for the xfail, but I think we need to resolve the pyright failures (in a separate PR?) before merging this if that's OK this could be a chance to address #2185 too |
|
All good - taking a look now Notes (Updating)
|
| @deprecated( | ||
| "Internally used for `numpy.ndarray` -> `CompliantSeries`\n" | ||
| "Also referenced in untyped `nw.dataframe.DataFrame._extract_compliant`\n" | ||
| "See Also:\n" | ||
| " - https://github.com/narwhals-dev/narwhals/pull/2149#discussion_r1986283345\n" | ||
| " - https://github.com/narwhals-dev/narwhals/issues/2116\n" | ||
| " - https://github.com/narwhals-dev/narwhals/pull/2169" | ||
| ) | ||
| def _create_compliant_series(self, value: Any) -> EagerSeriesT_co: ... |
There was a problem hiding this comment.
"Deprecated" is probably the wrong word.
I'm trying to mark it as something I want to replace with something like:
CompliantNamespace._series.from_numpy
CompliantNamespace._series.from_iterableThere are still some parts I wanna clear up first in the linked issues - hoping to explore that more in a future PR 🤞
There was a problem hiding this comment.
I don't think the current name is helpful in hinting that it is used for numpy - or at least it surprised me when I followed through the references
There was a problem hiding this comment.
cool, thanks! ok to move forwards then
There was a problem hiding this comment.
New usage of the method will show up in VSCode with a strikethrough and that message on hover
There was a problem hiding this comment.
But there isn't a runtime effect - purely for internal docs
MarcoGorelli
left a comment
There was a problem hiding this comment.
thanks @dangotbanned , great refactor here!
approving so we can move forwards with other work, I just left a question about why an internal method is deprecated
|
Thanks again for making it through this one @MarcoGorelli 😍 |

Closes #2044
What type of PR is this? (check all applicable)
Related issues
TypeVarused in(SparkLike|DuckDB)Expr#2044 (comment)CompliantExpr#2119 (comment)Compliant*sub-protocols #2055)_Stores(Native|Compliant)#2130CompliantSelector#2064Checklist
If you have comments or can explain your changes, please do so below
Direct follow-up to (#2119), aiming to make space for similar changes for other
Compliant*protocols.This PR spiralled a bit, but tackles a few quite-related issues.
Lazy-only typing
#2044 has been resolved through the use of the new protocol
NativeExpr.narwhals/narwhals/_compliant/expr.py
Lines 65 to 73 in b3bdb3b
(Arrow|PandasLike)*deduplicationAll of the new classes prefixed with
Eagernow provide the common functionality between the two Eager-only backends.The big one is
EagerExprnarwhals/narwhals/_compliant/expr.py
Lines 257 to 260 in b3bdb3b
A very unexpected part of that was that they could also share
*ExprNamespaceimplementationsProbably the most visual part of the PR as it removes the need for 12 modules
*NamespaceprotocolsWorking on the
Eagernamespaces led to the new generic protocols for both(expr|series)_*namespaces https://github.com/narwhals-dev/narwhals/blob/b3bdb3b3ba52dada9cadde3c50d68520f1270a09/narwhals/_compliant/any_namespace.pyThese can be re-used for all backends 😄
Misc
I followed up on (#2055 (comment)) and converted some methods to simpler
.from_variants.The only remaining one (
_create_compliant_series) is discussed in (#2149 (comment))I also opened (#2169) for following up some strange
pandasbehaviorNote
There might be some other bits in commit descriptions I've missed