-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add support to Import/Export table to/from dataframe #126
Conversation
Codecov Report
@@ Coverage Diff @@
## master #126 +/- ##
==========================================
- Coverage 83.09% 83.06% -0.04%
==========================================
Files 11 11
Lines 1384 1405 +21
Branches 244 250 +6
==========================================
+ Hits 1150 1167 +17
- Misses 156 159 +3
- Partials 78 79 +1
Continue to review full report at Codecov.
|
Sorry, for adding multiple commits, You can squash while merging. I tried but I was not able to squash these. I am not able to figure out why the formatting is failing. |
beautifultable/beautifultable.py
Outdated
@@ -30,6 +30,9 @@ | |||
import copy | |||
import csv | |||
import warnings | |||
from numpy import r_ | |||
|
|||
import pandas as pd |
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.
Can we make pandas
an optional dependency? so ideally just raise an exception inside the to_df
, from_df
methods if pandas is not installed. do make them required dependencies for the tests though. I think setup.py has fields for this scenario.
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.
Sure, will look into this.
test.py
Outdated
def test_df_import(self): | ||
table = BeautifulTable() | ||
table = table.from_df(self.df) | ||
self.assertEqual(self.table.rows.header, self.df.index) |
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.
we should also compare the cell values, not just the headers. also maybe add other unit tests to check the behavior in case headers are missing.
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.
Done
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 not use the _data attribute in the unit tests. private variable so only meant to be used from internal modules.
[list(row) for row in list(self.table._data)]
=> [list(row) for row in table.rows]
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.
Yes, I have changed this in beautifultable.py also. do you know I used [list(row) for row in table.rows]
while adding asdict API, don't know why I used _data here.
No probs, I am thinking of picking the row-span, column-span, and transpose features there I will get some good exposure to the design.
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.
spans might be tricky. needs some design before any implementations. I did start with something but found some gaps in the approach hence had to abandon the idea. but yeah, would love to see if you come up with an approach on how to implement these on their respective threads.
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.
Sure thing
@Agent-Hellboy added few comments. btw the formatting tests are failing because you haven't run |
Thanks for the quick review Priyam
Am I missing some flag while running |
@Agent-Hellboy Looks like formatting on master is also failing. I did test locally with the latest version of so somethink like
About annotations, can you open an issue for that. Better to track that in a separate thread. |
@pri22296 I got why formatting was failing. str literals are Unicode instead of bytes in 3.9, so I think we don't need to use u"" anymore. I was using black with 3.8. when I used the latest python nightly 3.11dev, it formatted test.py correctly. |
still failing for PyPy, Here people are saying in comments that |
@Agent-Hellboy For some reason, when using Pypy,
with python test.py This should fix the build errors. |
@pri22296 are you waiting for me to increase the code coverage, or you are busy in your work? |
@Agent-Hellboy apologies for the late reply. I can see that there are still few unresolved comments. could you please address those so we can go ahead with this change. |
are you talking about these two? I am waiting for your response on these two comments |
@Agent-Hellboy That's so weird. I don't see any comment from you in that thread. Can you maybe paste your comments here? must be some issue on github's end. |
Actually, they are allowing these things but later giving some intelligent response by taking some decision
It is allowing None as the header also
Done |
fixes #97