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

🐛 Resolved issue for data getter when datagrid is empty #358

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

ollyhensby
Copy link
Contributor

Issue number of the reported bug or feature request: #322

Describe your changes
Added an if statement to check the _data traitlet and see if its "data" value is empty within the data getter method. If it is empty, then construct an empty dataframe from the schema fields so final_df will be constructed from that df.

Testing performed
Re-ran the code in the issue.

  1. Create test DataGrid.
df = pd.DataFrame([1], columns=["a"])
grid = DataGrid(df)
grid

We get this output:
image

  1. Use data getter:
grid.data

image

  1. Now drop all the rows in the dataframe and set using the data setter.
grid.data = grid.data.drop(0)

We see that the DataGrid UI object reflects those changes (we only have the columns):

image

  1. Now call the data getter again:
grid.data
  1. Data getter now returns appropriate dataframe.

image

Additional context
No additional information.

@ollyhensby ollyhensby force-pushed the empty-df-getter-bug branch 6 times, most recently from ff609c1 to a913b40 Compare October 20, 2022 13:18
@ollyhensby
Copy link
Contributor Author

Tests to add:

  • pytest to check data getter works with empty dataframe (i.e. no rows).
  • Visual test to check DataGrid is correct based on the above.

@ibdafna
Copy link
Member

ibdafna commented Oct 24, 2022

@ollyhensby Thanks again for the contributions 🤩
To add a test, you can check out the test_datagrid.py in the test folder. You could follow the pattern of one of the existing tests in that file. The general gist is to create a datagrid object and assert the correct result is returned from .data under both conditions of the if-statement you added 😊Let me know if this doesn't make sense or you need help - happy to jump on a call!

Signed-off-by: Oliver Hensby <[email protected]>

Updated development installation in readme.md

Signed-off-by: Oliver Hensby <[email protected]>

Remove unused file-loader

Signed-off-by: Itay Dafna <[email protected]>

Migrate to hatch

Signed-off-by: martinRenou <[email protected]>

Release 1.1.13

Signed-off-by: Itay Dafna <[email protected]>

Exclude map files in production

Signed-off-by: martinRenou <[email protected]>

Update version, add file exclusions for packaging

Signed-off-by: Itay Dafna <[email protected]>
Signed-off-by: Oliver Hensby <[email protected]>

🎨 Ran black formatter

Formatted again. Docstring was too long
Copy link
Member

@ibdafna ibdafna left a comment

Choose a reason for hiding this comment

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

Awesome work. Thank you! 🌟

@@ -412,7 +412,12 @@ def __handle_custom_msg(self, _, content, buffers): # noqa: U101,U100
@property
def data(self):
trimmed_primary_key = self._data["schema"]["primaryKey"][:-1]
df = pd.DataFrame(self._data["data"])
if self._data["data"]:
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
if self._data["data"]:
if "data" in self._data:

If the "data" key doesn't exist in self._data then self._data["data"] will throw an error. This is a bit safer 😊

@ibdafna ibdafna merged commit 29ff164 into jupyter-widgets:main Nov 2, 2022
@ollyhensby ollyhensby deleted the empty-df-getter-bug branch January 14, 2023 14:01
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.

2 participants