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

[CHORE] Populate previews only when show() or __repr__() is called #1889

Merged
merged 7 commits into from
Feb 20, 2024

Conversation

colin-ho
Copy link
Contributor

@colin-ho colin-ho commented Feb 15, 2024

Closes #1858
Closes #1859

Changes:

  • no more preview creation in .collect()
  • added a _populate_preview method thats called during repr or show()
  • changed some tests

@github-actions github-actions bot added the chore label Feb 15, 2024
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (e47eeda) 85.55% compared to head (38fa51b) 85.55%.
Report is 7 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1889   +/-   ##
=======================================
  Coverage   85.55%   85.55%           
=======================================
  Files          55       55           
  Lines        6194     6216   +22     
=======================================
+ Hits         5299     5318   +19     
- Misses        895      898    +3     
Files Coverage Δ
daft/dataframe/dataframe.py 87.28% <100.00%> (-0.24%) ⬇️
daft/runners/pyrunner.py 96.17% <100.00%> (+0.24%) ⬆️
daft/runners/ray_runner.py 89.72% <100.00%> (+0.28%) ⬆️
daft/runners/partitioning.py 81.90% <50.00%> (-0.31%) ⬇️

... and 2 files with indirect coverage changes

@@ -24,7 +24,7 @@ def test_decimal_parquet_roundtrip() -> None:
df.write_parquet(dirname)
df_readback = daft.read_parquet(dirname).collect()

assert str(df.to_pydict()["decimal128"]) == str(df_readback.to_pydict()["decimal128"])
assert str(df.to_pydict()["decimal128"]) == str(df_readback.to_pydict()["decimal128"])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was weird, if i didn't do the indent, it would fail with:

../../daft/api_annotations.py:31: in _wrap
    return timed_method(*args, **kwargs)
../../daft/analytics.py:185: in tracked_method
    return method(*args, **kwargs)
../../daft/dataframe/dataframe.py:1316: in to_pydict
    return result.to_pydict()
../../daft/runners/partitioning.py:214: in to_pydict
    merged_partition = self._get_merged_vpartition()
../../daft/runners/pyrunner.py:52: in _get_merged_vpartition
    return MicroPartition.concat([part for id, part in ids_and_partitions])

@classmethod
    def concat(cls, to_merge: list[MicroPartition]) -> MicroPartition:
        micropartitions = []
        for t in to_merge:
            if not isinstance(t, MicroPartition):
                raise TypeError(f"Expected a MicroPartition for concat, got {type(t)}")
            micropartitions.append(t._micropartition)
>       return MicroPartition._from_pymicropartition(_PyMicroPartition.concat(micropartitions))
E       ValueError: DaftError::External Internal IO Error when Opening: /var/folders/nl/4tv7_psn7fq3n8sn6b4cpvw80000gn/T/tmputa6b7lc/ce958d3e-9fdc-48c3-9c8b-1917639037cd-0.parquet:
E       Details:
E       No such file or directory (os error 2)
```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh i see, .collect() creates an unloaded micropartition, so it didn't do any actual reading of the parquet data

@@ -24,48 +24,3 @@ def test_show_some(make_df, valid_data, data_source):
elif variant == "arrow":
assert df_display.preview.dataframe_num_rows == len(valid_data)
assert df_display.num_rows == 1


def test_show_from_cached_collect(make_df, valid_data):
Copy link
Contributor Author

@colin-ho colin-ho Feb 15, 2024

Choose a reason for hiding this comment

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

concept of 'cached_collect' doesn't exist anymore with this PR so i removed these tests

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess "cached" would be if we called __repr__() twice in a row now?

@colin-ho colin-ho marked this pull request as ready for review February 15, 2024 06:03
Copy link
Contributor

@jaychia jaychia left a comment

Choose a reason for hiding this comment

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

Nice! This will give us a nice speedup for cases where we were being really dumb about calculating the preview partitions :)

@@ -24,48 +24,3 @@ def test_show_some(make_df, valid_data, data_source):
elif variant == "arrow":
assert df_display.preview.dataframe_num_rows == len(valid_data)
assert df_display.num_rows == 1


def test_show_from_cached_collect(make_df, valid_data):
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess "cached" would be if we called __repr__() twice in a row now?

@colin-ho colin-ho force-pushed the colin/populate_preview_during_repr branch from c6c30a5 to 38fa51b Compare February 20, 2024 21:59
@colin-ho colin-ho merged commit b702e4d into main Feb 20, 2024
42 checks passed
@colin-ho colin-ho deleted the colin/populate_preview_during_repr branch February 20, 2024 22:12
samster25 pushed a commit that referenced this pull request Feb 27, 2024
…1889)

Closes #1858 
Closes #1859 

Changes:
 - no more preview creation in `.collect()`
- added a `_populate_preview` method thats called during `repr` or
`show()`
 - changed some tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only compute preview partition when needed Don't compute preview partitions for export methods
2 participants