- 
                Notifications
    You must be signed in to change notification settings 
- Fork 170
          refactor: adds _compliant sub-package
          #2149
        
          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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, thanks! ok to move forwards then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there isn't a runtime effect - purely for internal docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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