Comments (6)
The code seems to be taking an single list instead of numpy array below
from pandas.
original_list = func(y)
result = [[x] for x in original_list]
result = np.array(result)
This might help?
from pandas.
The problem exists in core\array_algos\datetimelike_accumulations.py
, _cum_func
:
result = func(y)
result[mask] = iNaT
Essentially, what this is doing is performing func
(np.cumsum
in this case) on your whole data array, and by default np.cumsum
computes the sum over a flattened array and returns it, but then when masking the NA values, it is expecting that the data array was in it's original shape and not flattened.
To fix this, you have to pass axis
as 0 to func
(again, np.cumsum
in this case), so that it performs the cumsum
along the given axis and not over the whole flattened array (it's the only func
with axis=None
by default, unlike cummin
and cummax
which have axis=0
by default and work properly)
I'd like to try fixing this issue, but it would be helpful to understand why the developers chose not to pass axis
to func
and instead handle its behavior internally.
And to explain why your other examples worked, in the first one, it did not use _cum_func
function, as the values were converted to a timedelta64[ns]
after computing the cumsum
, but in the second and third examples, it was handled well and only 1 column at a time was passed to _cum_func
(I couldn't trace back to how that was happening)
from pandas.
@phofl @mroeschke any comment on this based on #41720. I found result is 1D while mask is an array. Thus I tried
flattened_mask = mask.flatten()
result[flattened_mask] = iNaT
but ended up in error at
block = self.blocks[self.blknos[i]]
values = block.iget(self.blklocs[i])
bp = BlockPlacement(slice(0, len(values)))
in managers.py
from pandas.
take
from pandas.
Thanks @Aloqeely for helping me understand this.
from pandas.
Related Issues (20)
- DOC: Enforce Numpy Docstring Validation | pandas.Int16Dtype through pandas.IntervalIndex HOT 3
- BUG: KeyError: 'Step Nr.s' HOT 5
- DISC: Supporting numpy StringDType in Pandas HOT 7
- DOC: Enforce Numpy Docstring Validation | pandas.Series HOT 4
- DOC: Enforce Numpy Docstring Validation | pandas.Timestamp HOT 4
- DOC: `pd.concat` description of ordering when passing a mapping is unclear HOT 2
- TST: mutation testing results (possible tests to add)
- BUG: Pandas Overrides Default NumPy Function's Behavior
- BUG: DatetimeIndex.is_year_start breaks on double-digit frequencies HOT 6
- BUG: DatetimeIndex.is_year_start breaks for business-day frequency where `n` is greater than 1 HOT 4
- ENH: include cache in memory_usage
- BUG: wrong item assignment by repeated key with ArrowExtensionArray
- DOC: Table Visualization Style Guide Notebook does not work HOT 1
- DOC: Enforce Numpy Docstring Validation | pandas.tseries.offsets.Week to YearEnd HOT 1
- BUG: ewm with adjust=False and ignore_na=False does not properly take NaNs into account HOT 3
- DOC: Enforce Numpy Docstring Validation | pandas.api.extensions.ExtensionArray HOT 2
- BUG: convert_dtypes() doesn't convert after a previous conversion was done HOT 7
- DOC: convert_dtypes incorrectly assumes the output is a always DataFrame
- ENH: Add totality validation to merge method HOT 1
- BUG: pandas testsuite with numpy 2.0.0rc1 fails on numexpr HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandas.