feat: Add support for indices and values Series in Series.scatter#3444
feat: Add support for indices and values Series in Series.scatter#3444dangotbanned merged 16 commits intomainfrom
Series in Series.scatter#3444Conversation
| # - Missing return type | ||
| pc_replace_with_mask: Incomplete = pc.replace_with_mask | ||
| return self._with_native(pc_replace_with_mask(self.native, mask, values_native)) | ||
| def scatter(self, indices: Self, values: Self) -> Self: |
There was a problem hiding this comment.
This is very satisfying for (#3305) to finally pay off 🙏
Thought it might be worth splitting into a separate PR, since it would be easy to upstream to main and (possibly) avoid a
numpyimport
|
@FBruzzesi would you be open to me porting over the test suite as well? I'd need to make some tweaks, but I think I could get the diff negative 😄 (no worries if not) |
|
Sure @dangotbanned - I will first try to get the CI green again 🥦 🥦 Fixing CI is really the broccoli's to all the currently baking cakes 🍰 |
| @pytest.mark.filterwarnings( | ||
| "ignore:.*all arguments of to_dict except for the argument:FutureWarning" | ||
| ) |
There was a problem hiding this comment.
modin triggers this warning because it passes orient=list as positional.
So I copied over the filter from test_to_dict:
narwhals/tests/frame/to_dict_test.py
Lines 9 to 12 in 1a1d323
But I think we should either:
- Handle this in
narwhals - Add it to
tool.pytest.ini_options.filterwarnings
| assert_equal_data(df, unchanged_indexed) | ||
|
|
||
|
|
||
| def test_scatter_pandas_index() -> None: |
There was a problem hiding this comment.
I renamed this to make it clearer, since indices is a parameter name for scatter.
Although, I'd prefer if we could use a less direct way of testing index preservation.
E.g. if this is important, why only pandas and not all the derivatives?
narwhals/series.py
Outdated
| compliant_indices = self._extract_native(indices) | ||
| compliant_values = self._extract_native(values) |
There was a problem hiding this comment.
PR unrelated: Should we rename _extract_native to _extract_compliant?
There was a problem hiding this comment.
Lol, yeah I don't know when that slipped through 😂
There was a problem hiding this comment.
@FBruzzesi I thought I remembered discussing this!
Weirdly, the same thing has the wrong name on
nw.Series🤔Lines 376 to 381 in 0e80656
There was a problem hiding this comment.
@dangotbanned which algorithm do you use to index all past comments and conversations in your brain? I am jealous 😂
There was a problem hiding this comment.
@dangotbanned which algorithm do you use to index all past comments and conversations in your brain? I am jealous 😂
Deju vu + obsessive thoughts 😭
There was a problem hiding this comment.
PR unrelated: Should we rename
_extract_nativeto_extract_compliant?
@MarcoGorelli FYI, I will forget 😂
|
@dangotbanned let me know if you have time and manage to replicate the environment for which the tests are failing. I am on an Apple Silicon (macOS ARM64), and the old versions of pandas (1.1.3) and numpy (1.19.3) don't have pre-built wheels for this architecture. When pip/uv tries to build them from source, it fails 😭 Update: solved in 6b23fdc Might be nice to factor out Update 2: b714afb |
dangotbanned
left a comment
There was a problem hiding this comment.
Thanks @FBruzzesi!
I have a few suggestions, but overall just very happy to slowly creep #2572 into main 😉
|
@dangotbanned if you are happy (or I would say happier since the last approval in #3444 (review)) with this, I will go ahead and merge |
|
thanks all, solid! |

Description
@MarcoGorelli this might pop up in sklearn/skrub 😂
What type of PR is this? (check all applicable)
Related issues
scattershould acceptnarwhals.Seriesfor indices #2155Series.scatter#3305Checklist