79420889

Date: 2025-02-07 12:36:42
Score: 3
Natty:
Report link

As of today, on the latest 2.2 version of pandas, this correctly returns an empty Series if you apply on an empty dataframe. I have the same problem with 1.2 version where I have to explicitly add the result_type='reduce' argument while I dont have any problems with the 2.2 version.

E.g.,

import pandas as pd

df = pd.DataFrame(columns=['A', 'B'])
# only works in 1.2 version if I add result_type='ignore'
df['C'] = df.apply(lambda x: {x['A'], x['B']}, axis=1, result_type='reduce')

# works fine in 2.2 without any additional args
df['C'] = df.apply(lambda x: {x['A'], x['B']}, axis=1) 

Must have been a bug or smth in earlier versions.

Reasons:
  • Blacklisted phrase (1): I have the same problem
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same problem
  • Low reputation (0.5):
Posted by: dr_dronych