Skip to content
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

feat: support pd.Series.explode with ExtensionArray._explode method #46

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

douglasdavis
Copy link
Collaborator

Fix for #38

Now that pandas 2.2.0 is out we can implement this

@douglasdavis douglasdavis marked this pull request as draft January 22, 2024 22:15
data = ak.where(nums_filled == 0, [[None]], self._data)
flat = ak.flatten(data)
arr = type(self)(flat)
return arr, ak.num(data, axis=1)
Copy link
Member

Choose a reason for hiding this comment

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

When done on a series, what's the return type of explode()? Just curious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just a Series again. The two returns here are consumed by Series.explode, it uses the second return to build a new Index object and then passes the array and the index objects to Series._constructor:

https://github.com/pandas-dev/pandas/pull/54834/files#diff-a5257444a1b322d619680fc77361cc6ea11ef36b363b4bb2289fdef0f41feb70R4403

@CrfzdPQM6
Copy link

@martindurant suggested I paste this snippet here as a useful test:

import awkward as ak
values = [ak.Array([1.0,2.0,3.0]), ak.Array([4.0,5.0]), ak.Array([6.0])]
df = pd.DataFrame({'pt':values})

because the output of df.dtypes is that pt is object

I'm running into issues with pandas 2.2.1 that df.explode() does not work for a column with dtype awkward

@martindurant
Copy link
Member

df = pd.DataFrame({'pt':values})

needs to have dtype specified (or astype called) to make it awkward, else you are simply calling pandas' default iteration, which would also work for python lists.

@martindurant martindurant marked this pull request as ready for review April 16, 2024 15:01
@martindurant martindurant merged commit 36fc089 into intake:main Apr 16, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants