Skip to content

CLN: Cython Py2/3 Compatible Imports #23940

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 18 commits into from
Dec 26, 2018
Merged

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Nov 27, 2018

@jbrockmendel

@pep8speaks
Copy link

Hello @WillAyd! Thanks for submitting the PR.

  • There are no PEP8 issues in the file setup.py !

@WillAyd
Copy link
Member Author

WillAyd commented Nov 27, 2018

Main things needed to make this work were:

  1. Changing import machinery (95%)
  2. Handling difference in division (5%)
  3. Removed unicode from fused type with string / bytes object

Not entirely sure of the impact of the last. There is an alternate language setting in Cython we could use which uses Python3 but maintains 2 unicode semantics if this doesn't end up passing

@@ -54,10 +56,10 @@ cdef inline float64_t median_linear(float64_t* a, int n) nogil:
n -= na_count

if n % 2:
result = kth_smallest_c( a, n / 2, n)
result = kth_smallest_c( a, n // 2, n)
Copy link
Member

Choose a reason for hiding this comment

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

Space after open paren

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it changes with language-level, but in cython / defaults to cdivision, which behaves like python floor-division (... mostly. its corner cases are bizarre). The cython docs says there is a non-trivial perf impact of disabling cdivision. It might be worth checking how it treats floordiv.

Then again, this isn't an op we're doing zillions of times, so not a huge deal.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you try to just use / here compilation will fail as you try to assign a double to an int

@jbrockmendel
Copy link
Member

How strongly do you feel about absolute vs relative imports? These get pretty verbose.

@WillAyd
Copy link
Member Author

WillAyd commented Nov 27, 2018

Definitely more verbose but since we tend to favor absolute in the rest of the code base I think the consistency here is nice.

@jorisvandenbossche
Copy link
Member

I would be in favor of doing explicit relative imports here for imports within _libs

@WillAyd WillAyd changed the title Cython py3 lanuage_level CLN: Cython Py2/3 Compatible Imports Nov 28, 2018
@WillAyd WillAyd added the Clean label Nov 28, 2018
@WillAyd
Copy link
Member Author

WillAyd commented Nov 28, 2018

Just so I'm clear do you only want those imports to be relative from modules within the tslibs folder or from any module? For instance if you look at index.pyx it currently has:

from pandas._libs.tslibs.conversion cimport maybe_datetimelike_to_i8

So do we want this to be from .tslibs.conversion import maybe_datetimelike_to_i8 or should this stay absolute since it's not in the same directory?

Note that there is a .util module in the higher level directory and in tslibs. Full name spacing makes it a little bit clearer which one is being imported so I still slightly prefer that, but if I'm the odd man out on this one certainly glad to change

@WillAyd
Copy link
Member Author

WillAyd commented Nov 28, 2018

Side note - I repurposed this PR to just focus on imports for the time being. I think the actual changes to support Python3 syntax make more sense to do in a follow up. I think the unicode fused type is going to be finicky so may even wait for that until we officially drop Py2 support soon

@codecov
Copy link

codecov bot commented Dec 1, 2018

Codecov Report

Merging #23940 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #23940   +/-   ##
=======================================
  Coverage   42.46%   42.46%           
=======================================
  Files         161      161           
  Lines       51557    51557           
=======================================
  Hits        21892    21892           
  Misses      29665    29665
Flag Coverage Δ
#single 42.46% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b0610b...4d0437f. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 1, 2018

Codecov Report

Merging #23940 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23940      +/-   ##
==========================================
+ Coverage    92.3%   92.31%   +<.01%     
==========================================
  Files         163      163              
  Lines       51977    51977              
==========================================
+ Hits        47979    47980       +1     
+ Misses       3998     3997       -1
Flag Coverage Δ
#multiple 90.71% <ø> (ø) ⬆️
#single 42.99% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 87.84% <0%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b4b38f...b908e69. Read the comment docs.

@jbrockmendel
Copy link
Member

On further thought, I think Joris's suggestion is a really good one. A lot of effort has gone into making _libs modules, particularly _libs.tslibs self-contained. Using relative imports make it really obvious that a module has no one-level-up dependencies.

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.

let's just use absolute imports

On further thought, I think Joris's suggestion is a really good one. A lot of effort has gone into making _libs modules, particularly _libs.tslibs self-contained. Using relative imports make it really obvious that a module has no one-level-up dependencies.

this then is a departure from all other imports and so am -1 on this.

@@ -10,7 +10,7 @@ from cython import Py_ssize_t
from numpy cimport int64_t, int32_t

from locale import LC_TIME
from strptime import LocaleTime
from .strptime import LocaleTime
Copy link
Contributor

Choose a reason for hiding this comment

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

why not change this one?


from timedeltas cimport cast_from_unit
from timezones cimport (is_utc, is_tzlocal, is_fixed_offset,
from .ccalendar import DAY_SECONDS, HOUR_SECONDS
Copy link
Contributor

Choose a reason for hiding this comment

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

why are some of these relative? I think this is very confusing, I would rather have all absolute imports as we do elsewhere.

@WillAyd
Copy link
Member Author

WillAyd commented Dec 6, 2018

OK back to absolute @jreback PTAL

@jreback
Copy link
Contributor

jreback commented Dec 23, 2018

got lost in the mix, can you merge master.

@WillAyd
Copy link
Member Author

WillAyd commented Dec 25, 2018

Hypothesis test failure should be unrelated @jreback PTAL

@jreback jreback added this to the 0.24.0 milestone Dec 26, 2018
@jreback
Copy link
Contributor

jreback commented Dec 26, 2018

can you merge master. lgtm. ping on green.

@WillAyd
Copy link
Member Author

WillAyd commented Dec 26, 2018

@jreback green

@jreback jreback merged commit 1d86861 into pandas-dev:master Dec 26, 2018
@jreback
Copy link
Contributor

jreback commented Dec 26, 2018

thanks @WillAyd

@WillAyd WillAyd deleted the cython-py3-compat branch December 26, 2018 23:51
thoo added a commit to thoo/pandas that referenced this pull request Dec 28, 2018
* upstream/master: (26 commits)
  DOC: Fixing doc upload (no such remote origin) (pandas-dev#24459)
  BLD: for C extension builds on mac, target macOS 10.9 where possible (pandas-dev#24274)
  POC: _eadata (pandas-dev#24394)
  DOC: Correct location (pandas-dev#24456)
  CI: Moving CircleCI build to Travis (pandas-dev#24449)
  BUG: Infer compression by default in read_fwf() (pandas-dev#22200)
  DOC: Fix minor typo in whatsnew (pandas-dev#24453)
  DOC: Add dateutil to intersphinx pandas-dev#24437 (pandas-dev#24443)
  DOC: Adding links to offset classes in timeseries.rst (pandas-dev#24448)
  DOC: Adding offsets to API ref (pandas-dev#24446)
  DOC: fix flake8 issue in groupby.rst (pandas-dev#24363)
  DOC: Fixing more doc warnings (pandas-dev#24438)
  API: Simplify repeat signature (pandas-dev#24447)
  BUG: to_datetime(Timestamp, utc=True) localizes to UTC (pandas-dev#24441)
  CLN: Cython Py2/3 Compatible Imports (pandas-dev#23940)
  DOC: Fixing more doc warnings (pandas-dev#24431)
  DOC: Removing old release.rst (pandas-dev#24427)
  BUG-24408 Series.dt does not maintain own copy of index (pandas-dev#24426)
  DOC: Fixing several doc warnings (pandas-dev#24430)
  ENH: fill_value argument for shift pandas-dev#15486 (pandas-dev#24128)
  ...
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants