Skip to content

ENH: Integer NA Extension Array #21160

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

Merged
merged 23 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update for review comments
  • Loading branch information
jreback committed Jul 13, 2018
commit 4faa4c6a20db3c35d487b462f85c025a9a6f3ea0
9 changes: 5 additions & 4 deletions pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _concat_same_type(cls, to_concat):
return cls(data, mask=mask, dtype=to_concat[0].dtype)

def astype(self, dtype, copy=True):
"""Cast to a NumPy array with 'dtype'.
"""Cast to a NumPy array or IntegerArray with 'dtype'.

Parameters
----------
Expand All @@ -324,8 +324,8 @@ def astype(self, dtype, copy=True):

Returns
-------
array : ndarray
NumPy ndarray with 'dtype' for its dtype.
array : ndarray or IntegerArray
NumPy ndarray or IntergerArray with 'dtype' for its dtype.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify when what is returned?


Raises
------
Expand Down Expand Up @@ -502,7 +502,8 @@ def integer_arithmetic_method(self, other):
if isinstance(other, IntegerArray):
other, mask = other.data, other.mask
elif getattr(other, 'ndim', 0) > 1:
raise TypeError("can only perform ops with 1-d structures")
raise NotImplementedError(
"can only perform ops with 1-d structures")
elif is_list_like(other):
other = np.asarray(other)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try to convert to IntegerArray here if possible?
eg s + s.tolist() gives floats (in case s is a series with int-na dtype)

if not other.ndim:
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/integer/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ def test_error(self, data, all_arithmetic_operators):
ops(pd.Series(pd.date_range('20180101', periods=len(s))))

# 2d
with pytest.raises(TypeError):
with pytest.raises(NotImplementedError):
opa(pd.DataFrame({'A': s}))
with pytest.raises(TypeError):
with pytest.raises(NotImplementedError):
opa(np.arange(len(s)).reshape(-1, len(s)))


Expand Down