Skip to content

Annotate to_json #26449

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

Closed
wants to merge 8 commits into from
Closed

Annotate to_json #26449

wants to merge 8 commits into from

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented May 18, 2019

Simple annotations as I was looking at the code

@gwrome and @vaibhavhrt

@WillAyd WillAyd added the Typing type annotations, mypy/pyright type checking label May 18, 2019
@pep8speaks
Copy link

pep8speaks commented May 18, 2019

Hello @WillAyd! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-18 22:38:54 UTC

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.

i would really not use Any unless
we have no other way

@@ -67,7 +68,7 @@ def _is_url(url):
return False


def _expand_user(filepath_or_buffer):
def _expand_user(filepath_or_buffer: Any) -> Any:
Copy link
Contributor

@jreback jreback May 18, 2019

Choose a reason for hiding this comment

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

FilePathOrBuffer

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea was thinking that too. My motivation for putting Any was that these methods truly do accept anything though and could just return the caller so it's a literal interpretation of that feature, though static typing would detect potential abuses.

Pushing up in next commit

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.

really limit the use of Any

@codecov
Copy link

codecov bot commented May 18, 2019

Codecov Report

Merging #26449 into master will decrease coverage by 50.03%.
The diff coverage is 69.23%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #26449       +/-   ##
===========================================
- Coverage   91.73%   41.69%   -50.04%     
===========================================
  Files         174      174               
  Lines       50754    50758        +4     
===========================================
- Hits        46560    21165    -25395     
- Misses       4194    29593    +25399
Flag Coverage Δ
#multiple ?
#single 41.69% <69.23%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/io/common.py 56.85% <100%> (-34.99%) ⬇️
pandas/io/json/json.py 63.19% <60%> (-30.05%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/core/groupby/categorical.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.37%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.16%) ⬇️
pandas/io/sas/sas_xport.py 0% <0%> (-90.1%) ⬇️
... and 131 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 80bddaf...98bea68. Read the comment docs.

@codecov
Copy link

codecov bot commented May 18, 2019

Codecov Report

Merging #26449 into master will decrease coverage by <.01%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26449      +/-   ##
==========================================
- Coverage   91.73%   91.73%   -0.01%     
==========================================
  Files         174      174              
  Lines       50754    50758       +4     
==========================================
+ Hits        46560    46561       +1     
- Misses       4194     4197       +3
Flag Coverage Δ
#multiple 90.23% <90.9%> (ø) ⬆️
#single 41.69% <72.72%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/io/json/json.py 93.28% <100%> (+0.04%) ⬆️
pandas/io/common.py 92.38% <83.33%> (+0.54%) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97.02% <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 80bddaf...223f7ca. Read the comment docs.

if _PY_PATH_INSTALLED and isinstance(filepath_or_buffer, LocalPath):
return filepath_or_buffer.strpath
return _expand_user(filepath_or_buffer)
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to refactor this because Mypy wasn't narrowing types at this point and still guessed that Path objects could be returned here based off of the signature of _expand_user even though the preceding isinstance check wouldn't allow that.

I commented on python/mypy#6847 (comment) so will see if that gets any attention, but the refactor works as well

@@ -82,6 +87,8 @@ def _expand_user(filepath_or_buffer):
"""
if isinstance(filepath_or_buffer, str):
return os.path.expanduser(filepath_or_buffer)
elif isinstance(filepath_or_buffer, pathlib.Path):
Copy link
Member Author

Choose a reason for hiding this comment

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

We weren't expanding Path objects with existing code so this should handle that as well. Reviewing where to add test for this

Copy link
Member Author

Choose a reason for hiding this comment

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

Might split this off into a separate issue/PR if I can find a bug using Path objects not expanding

@WillAyd
Copy link
Member Author

WillAyd commented May 27, 2019

Will come back to this at a later date

@WillAyd WillAyd closed this May 27, 2019
@WillAyd WillAyd deleted the type-to-json branch January 16, 2020 00:34
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.

3 participants