Skip to content

Remove Python2 numeric relics #38916

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

Merged
merged 3 commits into from
Jan 3, 2021
Merged

Remove Python2 numeric relics #38916

merged 3 commits into from
Jan 3, 2021

Conversation

eumiro
Copy link
Contributor

@eumiro eumiro commented Jan 3, 2021

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Modernize the code to Python 3 by removing Python 2 numeric hacks, such as:

  • a / b of two integers now always returns a float, so no need to convert a and/or b to float (or to use float literals)
  • a // b of two integers returns an integer, use it instead of int(a / b)
  • math.ceil, math.floor, and round return integer, so no need to convert the result to integer
  • 1e6 is a float, converting it to int(1e6) is slower than 10 ** 6 (or 1_000_000)

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice, thanks @eumiro !

Did you use some tool to find these, or was it just inspection?

@eumiro
Copy link
Contributor Author

eumiro commented Jan 3, 2021

Nice, thanks @eumiro !

Did you use some tool to find these, or was it just inspection?

Thank you. It was manual search&replace (with at least one typo as you could see, thank you, fixed, repushed), because every case is different. Usually it is a good idea to search for int(, float(, round, math., \de\d, \d\.0\b, etc.

@jreback jreback added this to the 1.3 milestone Jan 3, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

thanks @eumiro very nice

@jreback jreback merged commit f9ce9d6 into pandas-dev:master Jan 3, 2021
@eumiro eumiro changed the title Remove Python2 numeric relicts Remove Python2 numeric relics Jan 5, 2021
@eumiro eumiro deleted the py2numbers branch January 5, 2021 07:10
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
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