Skip to content

'IntegerArray' object has no attribute 'T' #32342

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

Closed
bnaul opened this issue Feb 28, 2020 · 7 comments
Closed

'IntegerArray' object has no attribute 'T' #32342

bnaul opened this issue Feb 28, 2020 · 7 comments
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Needs Tests Unit test(s) needed to prevent regressions

Comments

@bnaul
Copy link
Contributor

bnaul commented Feb 28, 2020

In our case this arose via .cumsum():

pd.Series([0, 1], dtype='int64').cumsum()
0    0
1    1
dtype: int64

pd.Series([0, 1], dtype='Int64').cumsum()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-31-2ebc3e3cf698> in <module>
----> 1 pd.Series([0, 1], dtype='Int64').cumsum()
...

~/model/.venv/lib/python3.7/site-packages/pandas/core/generic.py in na_accum_func(blk_values)
  11324                 np.putmask(result, mask, mask_b)
  11325             else:
> 11326                 result = accum_func(blk_values.T, axis)
  11327
  11328             # transpose back for ndarray, not for EA

AttributeError: 'IntegerArray' object has no attribute 'T'

But it's also true that just calling .values.T on a regular int array works (just a no-op), whereas on an Int64 array it does not. Same is true for

Any reason not to just add a no-op .T on the base ExtensionArray class..? cc @TomAugspurger in case you have an opinion 🙂

@TomAugspurger
Copy link
Contributor

In the past we've been hesitant to add useless methods to EAs simply because ndarrays have them. I'm not sure about adding it here.

@bnaul
Copy link
Contributor Author

bnaul commented Feb 28, 2020

Makes sense; surely .cumsum() is not useless though 🙂. Would the right approach then be to have a separate implementation of that...?

@jorisvandenbossche jorisvandenbossche added the ExtensionArray Extending pandas with custom dtypes or arrays. label Feb 29, 2020
@jorisvandenbossche
Copy link
Member

cumsum is indeed useful, but should be implemented specifically for EAs probably, without requiring T.
There is an open PR related to this (#28509), but didn't check the status of it.

@jbrockmendel
Copy link
Member

In the past we've been hesitant to add useless methods to EAs simply because ndarrays have them

This statement is technically correct (the best kind of correct), but there is not at all consensus that "T" is useless. This is just one more in a large pile of things that could be made easier.

@TomAugspurger
Copy link
Contributor

As I said, it’s useless on its own for EAs. It’s potential use comes from writing code that works with both EAs and ndarrays.

@jbrockmendel
Copy link
Member

jbrockmendel commented Sep 17, 2020

the example from the OP works on master, could use test

update: it loses dtype

@jbrockmendel jbrockmendel added the Needs Tests Unit test(s) needed to prevent regressions label Sep 17, 2020
@mzeitlin11
Copy link
Member

Closing in favor of #28385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

No branches or pull requests

5 participants