0

I am new to pandas and not familiar with the history of the changes. I have code that I am trying to make work on the latest version of pandas. The last version it works with is 1.1.5. pandas 1.2.0 breaks the code with no other dependencies changing.

The code is doing a SeriesA / SeriesB. SeriesB has some zeros inside. When this division is done with pandas 1.1.5, the zeros division becomes NaNs which is fine. However, when this division is done with pandas 1.2.0, it throws a division by zero error.

Is there some setting I can make that makes the latest pandas treat division by zero with NaNs?

I did some debugging into pandas 1.1.5 vs. pandas 1.2.0. When run with pandas 1.1.5 (which works), the numerator SeriesA is of dtype float64 and the denominator SeriesB is also of dtype float64. However, when run with pandas 1.2.0 (which fails), the numerator SeriesA is of dtype object and the denominator SeriesB is still dtype float64. So success is float64/float64 and failure is object/float64

scastria
  • 51
  • 7
  • It'd help to make a [mre]. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). – wjandrea Oct 28 '22 at 22:18
  • 1
    @scastria If you have more information to add, click the `Edit` link, don't put it in comments. – Barmar Oct 28 '22 at 23:11
  • 1
    So the problem seems to be with how you're loading the data into SeriesA. Something in the data is not numeric, so it's making a series of objects instead of numbers. – Barmar Oct 28 '22 at 23:18
  • 1
    Use ```pandas.to_numeric()``` to the SeriesA. And I recommend to use Pandas 1.5. – relent95 Oct 29 '22 at 01:51

0 Answers0