-
Notifications
You must be signed in to change notification settings - Fork 117
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
Partly fix #1493: error message changed #1515
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
import narwhals.stable.v1 as nw | ||
|
||
np = nw.dependencies.get_numpy() | ||
pd = nw.dependencies.get_pandas() | ||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can just import these directly here (though if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. I can confirm that |
||
|
||
|
||
def test_index() -> None: | ||
s = pd.Series([0, 1, 2]) | ||
snw = nw.from_native(s, series_only=True) | ||
assert snw[snw[0]] == np.int64(0) | ||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use s = nw.from_native(constructor_eager({'a': [0,1,2]}), eager_only=True)['a']
assert s[s[0]] == 0
``` There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't understand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks @thevro ! yeah There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done #1554 if you fetch upstream and then merge upstream/main then the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And doing import pyarrow as pa
from pyarrow import compute as pc
pazero = pc.cast(0, pa.int64())
...
idx = snw[0] # test indexing using builtin int
assert idx == 0 or idx == pazero # idx should have type numpy.int64 or pa.int64
assert snw[idx] == 0 or idx == pazero # test indexing using third-party int produces a test error: > assert snw[idx] == 0 or idx == pazero # test indexing using numpy.int64
tests/series_only/scalar_index_test.py:19:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
narwhals/series.py:73: in __getitem__
return self._from_compliant_series(self._compliant_series[idx])
narwhals/_arrow/series.py:378: in __getitem__
return self._from_native_series(self._native_series[idx])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E TypeError: 'pyarrow.lib.Int64Scalar' object cannot be interpreted as an integer
pyarrow/table.pxi:312: TypeError I suppose this comes of handling only numpy scalars. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, fixed now, if you fetch and merge upstream/main 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.
can we check
(is_numpy_scalar(idx) and idx.dtype.kind in ('i', 'u'))
?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.
As I understand it, we would ideally capture any sort of numpy scalar that can be used to index a pandas series. Can't strings, floats and datetime objects also be used?
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.
no, we only allow positional indexing here