Skip to content
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

First attempt: panedr and panedrlite #42

Merged
merged 26 commits into from
Jul 6, 2022
Merged

Conversation

BFedder
Copy link
Collaborator

@BFedder BFedder commented Jun 26, 2022

This is the first attempt at creating an empty panedr package that relies on a "panedrlite" package, so will very likely still need quite a bit of work put into it.

That being said, the way this is organised now allows for panedrlite to be pip-installed. With panedrlite installed, the empy panedr can be installed as well. In the process, pandas is automatically installed. The functions are loaded into the panedr namespace, so can be called as they are now (i.e. panedr.edr_to_df())

I'm hoping that once panedrlite is on PyPI, panedr can be installed without prior installation of panedrlite.

@pep8speaks
Copy link

pep8speaks commented Jun 26, 2022

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

Line 7:1: E402 module level import not at top of file

Line 7:1: E402 module level import not at top of file

Line 4:5: E128 continuation line under-indented for visual indent
Line 5:5: E128 continuation line under-indented for visual indent
Line 6:1: E124 closing bracket does not match visual indentation

Comment last updated at 2022-07-05 15:58:06 UTC

@codecov
Copy link

codecov bot commented Jun 26, 2022

Codecov Report

Merging #42 (a04eaf0) into master (84bd117) will decrease coverage by 82.84%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #42       +/-   ##
==========================================
- Coverage   82.84%   0.00%   -82.85%     
==========================================
  Files           2       2               
  Lines         274     279        +5     
==========================================
- Hits          227       0      -227     
- Misses         47     279      +232     
Impacted Files Coverage Δ
panedrlite/panedrlite/__init__.py 0.00% <0.00%> (ø)
panedrlite/panedrlite/panedr.py 0.00% <0.00%> (ø)
panedr/panedr/__init__.py

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 84bd117...a04eaf0. Read the comment docs.

@BFedder
Copy link
Collaborator Author

BFedder commented Jun 26, 2022

I can't seem to get codecov to be happy with these changes, even though the tests pass... Could someone please help me fix this?

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

The codecov stuff is annoying but I have a suspicion it's actually on the codecov side of things - running pytest locally and generating a coverage file works fine with the expected line coverage. I suspect this is because codecov doesn't understand what's going on in the branch, the first here is probably just to merge and see if codecov fixes itself imho.


- name: run unit tests
run: |
pytest -n 2 -v --cov=panedr --cov-report=xml --color=yes ./tests
pytest -n 2 -v --cov=panedrlite --cov-report=xml --color=yes ./tests
Copy link
Member

Choose a reason for hiding this comment

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

You can revert this back to panedrlite/panedrlite

@@ -56,11 +56,12 @@ jobs:

- name: install package
run: |
python -m pip install -v .
python -m pip install -v ./panedrlite
# python -m pip install -v ./panedr
Copy link
Member

Choose a reason for hiding this comment

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

we should add an extra step to check imports and make sure stuff works.

Something like this would do the trick (not tested the working-directory line so 🤞🏽 )

- name: test imports
  # Exit the git repo in order for pbr to stop auto-picking up version info from the local git data
  working-directory: ../
  run: |
    python -Ic "from panedrlite import edr_to_dict"
    python -lc "from panedr import edr_to_df"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

python -lc "from panedr import edr_to_df"

So presumably I will need to uncomment line 60 (python -m pip install -v ./panedr), right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have done this now, I guess we will only see on merge if the import test works?

panedrlite/panedrlite/__init__.py Show resolved Hide resolved
Does not roll the reading position back.
"""
magic = data.unpack_int()
return magic == -7777777


def edr_to_df(path, verbose=False):
def read_edr(path, verbose=False):
Copy link
Member

Choose a reason for hiding this comment

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

Does this PR supersede #33 or is it meant to follow it? (i.e. which should get merged first)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I didn't mean to create this branch here from my branch for #33... Too new to using git still. #33 should probably be merged first, or at least the changes approved. Alternatively, I could replace this version of panedr.py with the one from the master branch (as I originally intended)

@@ -14,7 +14,7 @@
import contextlib
import numpy
import pandas
import panedr
import panedrlite as panedr
import re

# On python 2, cStringIO is a faster version of StringIO. It may not be
Copy link
Member

Choose a reason for hiding this comment

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

Can you fix these imports to be py3+ only now? The py2 code paths aren't necessary anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@BFedder
Copy link
Collaborator Author

BFedder commented Jun 29, 2022

Now that #33 is merged, should we try merging this PR here as well to see if codecov can fix itself, and if test imports is working?

@BFedder
Copy link
Collaborator Author

BFedder commented Jun 29, 2022

I have now also added type hints and docstrings to address #30 and #31.
This is the first time I have tried to add type hints for nested lists, so I am not sure if this is actually going to work as intended.
Also, the type hint for the return type of edr_to_df needs work: Without pandas imported, this doesn't work. Adding a try-except statement around the function definition is one way around that, but if pandas isn't installed and the function thus not defined, the user will never trigger the ImportError telling them to install pandas if they try to call edr_to_df... I think the best option here would be to omit the type hint in the function definition and, if needed, replace it with a type assertion like assert type(df) == pandas.DataFrame?

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Nitpicks on a type hint but shaping up well. I will need to clone your branch to test how it works, will hopefully provide a more content heavy review over next few days.

@@ -403,7 +411,37 @@ def is_frame_magic(data):
return magic == -7777777


def read_edr(path, verbose=False):
all_energies_type = list[list[float]]
Copy link
Member

Choose a reason for hiding this comment

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

Personal opinion but I prefer type hints to be in full at the call site where possible.

I get that here they are too long and complicated to be readable and am happy with your choice but just where possible.

return all_energies, all_names, times



def edr_to_df(path: str, verbose: bool = False):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def edr_to_df(path: str, verbose: bool = False):
def edr_to_df(path: str, verbose: bool = False) -> pd.DataFrame:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a bit complicated because pandas is an optional dependency. If pandas is not installed, the module can't be imported if the type hint is present. I could put the function definition into a try-except statement, but then I would lose the custom ImportError message. What's the best thing to do here?

Copy link
Member

Choose a reason for hiding this comment

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

My 2 cents - sometimes you just have to take the loss. Type hints are just that, over-engineering a solution for an optional import for a method that's ~ 3 lines of code probably isn't worth it.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I took one of the suggestions from there and it seems to work :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Spoke to soon - I didn't fully think this through, the solution I tried yesterday won't work I'm afraid. I think we'll have to hold back on annotating the return type of edr_to_df for now, but the function name and doc string are pretty self-explanatory, and mypy wasn't working with that anyway yet

mypy error message: "error: Skipping analyzing "pandas": module is installed, but missing library stubs or py.typed marker
panedrlite/panedrlite/panedr.py:59: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports"

Copy link
Member

Choose a reason for hiding this comment

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

I would say don't worry about it. We lived without typed code for Python 0-3.whatever so I'm sure well be fine without it. Sorry for leading you down the garden path.

@IAlibay IAlibay mentioned this pull request Jun 30, 2022
3 tasks
@IAlibay IAlibay added this to the 0.6.0 milestone Jun 30, 2022
@BFedder
Copy link
Collaborator Author

BFedder commented Jul 4, 2022

This PR would address issues #30, #31, and #34 on merging, and once that's done we can think about deployment (thanks @IAlibay for volunteering here!). Afterwards, work on the EDRReader can start in earnest. Can I ask for any remaining reviewer comments @hmacdope @IAlibay @orbeckst @jbarnoud?

orbeckst
orbeckst previously approved these changes Jul 4, 2022
Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

The code & packaging looks ok to me. I have some minor comments but nothing blocking.

I don't understand why codecov is unhappy, perhaps because of the major renaming. Presumably, this can be fixed once the PR is merged and we have the new repo structure in place.

README.rst Outdated Show resolved Hide resolved
panedr/panedr/__init__.py Outdated Show resolved Hide resolved
panedrlite/panedrlite/__init__.py Outdated Show resolved Hide resolved
@orbeckst
Copy link
Member

orbeckst commented Jul 5, 2022

We will have to relax the branch protection to merge—unless someone has an idea how to get coverage to report a high number.

@IAlibay
Copy link
Member

IAlibay commented Jul 5, 2022

We will have to relax the branch protection to merge—unless someone has an idea how to get coverage to report a high number.

I've dropped the include administrator requirement in the branch protection (and also added require PR for extra safety). That should allow all admins to tick the "merge without waiting for requirements to be met" box.

I think all org admins are admins by default, but we can manually add admins if necessary.

IAlibay
IAlibay previously approved these changes Jul 5, 2022
Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Aside from @orbeckst's comments, this lgtm! (I'll approve early)

@jbarnoud
Copy link
Collaborator

jbarnoud commented Jul 5, 2022

Could the panedrlite module not expose import panedrlite? Ideally, pip install panedrlite would just let you do import panedr.

Anyway, I am fine with it.

@BFedder BFedder dismissed stale reviews from IAlibay and orbeckst via ff328c3 July 5, 2022 15:29
@BFedder
Copy link
Collaborator Author

BFedder commented Jul 5, 2022

Could the panedrlite module not expose import panedrlite? Ideally, pip install panedrlite would just let you do import panedr.

Anyway, I am fine with it.

I think this is working now - I renamed panedrlite/panedrlite to panedrlite/panedr, and now it can be imported with import panedr

@BFedder
Copy link
Collaborator Author

BFedder commented Jul 5, 2022

Turns out, renaming panedrlite to panedr makes things quite complicated for CI testing... Everything works locally, but the import test fails like this. I have looked around for a while on how to expose different import names, but I think this would be the way to have panedrlite be importable as panedr. My suggested solution here is to go back to having it be import panedrlite and recommend people do import panedrlite as panedr. This way the CI would work again.

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

lgtm (again)

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

LGTM also

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

How odd Github just didn't assign my approval - I'll see if I can make the merge happen 😅

@IAlibay IAlibay merged commit 927ad03 into MDAnalysis:master Jul 6, 2022
@hmacdope
Copy link
Member

hmacdope commented Jul 6, 2022

Phew because I was scared of the command line merge 😅.

@BFedder BFedder mentioned this pull request Jul 6, 2022
ezavod pushed a commit to ezavod/panedr that referenced this pull request Jul 9, 2022
PR MDAnalysis#42
## Work done in this PR
* Creates the panedr and panedrlite packages
* panedrlite is panedr without pandas
* panedr import panedrlite and pandas
* update CI accordingly
* fix some type hint issues
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.

6 participants