Skip to content

TYP: Adding absolute imports for pandas.core.reshape #25936

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

Conversation

ryankarlos
Copy link
Contributor

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Can you remove these from mypy.ini as well?

@ryankarlos
Copy link
Contributor Author

Removed concat and tile from mypy.ini. I've not made any changes to imports for merge module due to issue mentioned in #25934 regarding pandas._libs

@WillAyd
Copy link
Member

WillAyd commented Mar 31, 2019

Is that failing for you locally? Curious if you are able to investigate root cause

@WillAyd WillAyd added the Typing type annotations, mypy/pyright type checking label Mar 31, 2019
@codecov
Copy link

codecov bot commented Mar 31, 2019

Codecov Report

Merging #25936 into master will decrease coverage by 49.9%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #25936       +/-   ##
===========================================
- Coverage   91.81%   41.91%   -49.91%     
===========================================
  Files         175      175               
  Lines       52580    52592       +12     
===========================================
- Hits        48278    22044    -26234     
- Misses       4302    30548    +26246
Flag Coverage Δ
#multiple ?
#single 41.91% <100%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/reshape/tile.py 15% <100%> (-82.68%) ⬇️
pandas/core/reshape/concat.py 44.88% <100%> (-52.32%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/tseries/converter.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-99.36%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-95.46%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.16%) ⬇️
pandas/io/sas/sas_xport.py 0% <0%> (-90.1%) ⬇️
... and 132 more

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 de3a85c...86266de. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 31, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25936      +/-   ##
==========================================
- Coverage    91.9%   91.89%   -0.01%     
==========================================
  Files         175      175              
  Lines       52485    52485              
==========================================
- Hits        48234    48230       -4     
- Misses       4251     4255       +4
Flag Coverage Δ
#multiple 90.45% <ø> (ø) ⬆️
#single 40.75% <ø> (-0.14%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 75% <0%> (-12.5%) ⬇️
pandas/core/frame.py 96.79% <0%> (-0.12%) ⬇️

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 a07ed59...87a8ea4. Read the comment docs.

@ryankarlos
Copy link
Contributor Author

Is that failing for you locally? Curious if you are able to investigate root cause

No I didn't run any test locally - i can try and report back if that helps

@ryankarlos
Copy link
Contributor Author

Just tried running tests locally with importing join from pandas._libs in merge module - seems to be running ok but not sure if it will throw an error when checks run on pushing.

@WillAyd WillAyd added this to the 0.25.0 milestone Mar 31, 2019
import pandas.core.algorithms as algos
from pandas.core.arrays.categorical import Categorical
Copy link
Contributor

Choose a reason for hiding this comment

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

@WillAyd this is going to make
imports much longer

no way to simply import from pandas
directly?

Copy link
Member

Choose a reason for hiding this comment

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

When you say longer you just mean more lines right? I thought this was desired from conversation in #25923

Copy link
Contributor

Choose a reason for hiding this comment

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

i was thinking just for frame / series but now i see for everything

this is pretty jarring - is there anyway to do this w/o going all the way here?

Copy link
Member

Choose a reason for hiding this comment

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

So here's a relevant issue I found on the MyPy tracker:

python/mypy#4930

I think there's a few ways to go about this which aren't mutually exclusive:

  1. Go with path above of explicitly import objects where they are defined internally
  2. Replace wildcard imports in top level init with actual objects
  3. Wait for new mypy semantic analyzer (note I tried current dev version and it raised AssertionError, so not sure how far out this would be or if viable)
  4. Stub out top level pandas objects

I think we want number 4 at the end of the day and ultimately would want to put something like that in TypeShed, but my thought was that is still going to take some effort to generate correctly and it would be good to get our blacklist of items whittled down first before focusing on that.

While number 1 above is more verbose I think it has the added bonus of making our internal import machinery more explicit, so I'd still vouch for it here

Copy link
Contributor

Choose a reason for hiding this comment

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

we should just do this: Replace wildcard imports in top level init with actual objects, this is much better that changing everything else. @WillAyd can you make an issue for this (though you have one about changing to absolute imports everywhere)

@WillAyd
Copy link
Member

WillAyd commented Mar 31, 2019 via email

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Apr 1, 2019

@WillAyd @jreback Does this need any further updates ?

Copy link
Contributor Author

@ryankarlos ryankarlos left a comment

Choose a reason for hiding this comment

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

@WillAyd @jreback These are two additional places which required top level import after reverting all other changes - ive added them in latest commits.

Copy link
Contributor Author

@ryankarlos ryankarlos left a comment

Choose a reason for hiding this comment

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

@WillAyd these are two other places which required top level imports after reverting all changes in this PR. Ive added them in latest commits

@@ -2,20 +2,20 @@
concat routines
"""

import numpy as np

import pandas.core.dtypes.concat as _concat
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here

from pandas._libs.lib import infer_dtype

from pandas.core.dtypes.common import (
_NS_DTYPE, ensure_int64, is_categorical_dtype, is_datetime64_dtype,
is_datetime64tz_dtype, is_datetime_or_timedelta_dtype, is_integer,
is_scalar, is_timedelta64_dtype)
from pandas.core.dtypes.missing import isna
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here

@WillAyd
Copy link
Member

WillAyd commented Apr 10, 2019

Similar comment in the other issue - right now keeping focus on typing so if it works by just removing blacklist items let's stick to that.

Certainly don't want to import numpy from the pandas namespace

@ryankarlos
Copy link
Contributor Author

ok just reverted the changes now

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Can you completely revert changes to concat and tile? Just keeps changes to mypy config


from pandas import DataFrame, Index, MultiIndex, Series, compat
from pandas import (
DataFrame, Index, MultiIndex, Series, compat, concat as _concat)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is causing a build failure

@ryankarlos ryankarlos force-pushed the Typing_fixups_pandas.core.reshape branch from 17f8172 to 7755c8e Compare April 10, 2019 17:55
@ryankarlos ryankarlos force-pushed the Typing_fixups_pandas.core.reshape branch from 7755c8e to ad8ca67 Compare April 10, 2019 23:56
@WillAyd
Copy link
Member

WillAyd commented Apr 11, 2019

@ryankarlos looks OK and doubt CI failures are related but can you merge master and repush?

FYI merging master is strongly preferred to rebasing and shouldn't require a force push. Your workflow should look something like this on your local branch:

git fetch upstream
git merge upstream master
# Fix up merge conflicts if any
# git merge --continue
git push origin YOUR_BRANCH

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Apr 11, 2019

@WillAyd @jreback Just merged master and re-pushed - but not sure why tests fail for linux py36 and py37 -- difficult to discern root cause from error log - maybe due to something unrelated ?

@WillAyd
Copy link
Member

WillAyd commented Apr 15, 2019

Test failures were unrelated and disappeared on restart of CI. This is pretty stripped down from original request and looks good so moving forward with merge.

Thanks @ryankarlos

@WillAyd WillAyd merged commit d86553b into pandas-dev:master Apr 15, 2019
yhaque1213 pushed a commit to yhaque1213/pandas that referenced this pull request Apr 22, 2019
@ryankarlos ryankarlos changed the title Adding absolute imports for pandas.core.reshape TYP:Adding absolute imports for pandas.core.reshape Oct 10, 2019
@ryankarlos ryankarlos changed the title TYP:Adding absolute imports for pandas.core.reshape TYP: Adding absolute imports for pandas.core.reshape Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assorted Typing Fixups in pandas.core.reshape
3 participants