-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
Main things needed to make this work were:
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 |
pandas/_libs/groupby.pyx
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after open paren
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
How strongly do you feel about absolute vs relative imports? These get pretty verbose. |
Definitely more verbose but since we tend to favor absolute in the rest of the code base I think the consistency here is nice. |
I would be in favor of doing explicit relative imports here for imports within |
Just so I'm clear do you only want those imports to be relative from modules within the from pandas._libs.tslibs.conversion cimport maybe_datetimelike_to_i8 So do we want this to be Note that there is a |
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 |
Codecov Report
@@ Coverage Diff @@
## master #23940 +/- ##
=======================================
Coverage 42.46% 42.46%
=======================================
Files 161 161
Lines 51557 51557
=======================================
Hits 21892 21892
Misses 29665 29665
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #23940 +/- ##
==========================================
+ Coverage 92.3% 92.31% +<.01%
==========================================
Files 163 163
Lines 51977 51977
==========================================
+ Hits 47979 47980 +1
+ Misses 3998 3997 -1
Continue to review full report at Codecov.
|
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. |
There was a problem hiding this 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.
pandas/_libs/tslibs/ccalendar.pyx
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
pandas/_libs/tslibs/conversion.pyx
Outdated
|
||
from timedeltas cimport cast_from_unit | ||
from timezones cimport (is_utc, is_tzlocal, is_fixed_offset, | ||
from .ccalendar import DAY_SECONDS, HOUR_SECONDS |
There was a problem hiding this comment.
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.
OK back to absolute @jreback PTAL |
got lost in the mix, can you merge master. |
Hypothesis test failure should be unrelated @jreback PTAL |
can you merge master. lgtm. ping on green. |
@jreback green |
thanks @WillAyd |
* 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) ...
git diff upstream/master -u -- "*.py" | flake8 --diff
@jbrockmendel