Skip to content

Fix python examples tests not running in Dataflow - #23546

Merged
TheNeuralBit merged 8 commits into
apache:masterfrom
benEng:bug-python-examples
Nov 1, 2022
Merged

Fix python examples tests not running in Dataflow#23546
TheNeuralBit merged 8 commits into
apache:masterfrom
benEng:bug-python-examples

Conversation

@benEng

Copy link
Copy Markdown
Contributor

Resolves#22983


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI.

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Direct

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Dataflow

@benEng

Copy link
Copy Markdown
ContributorAuthor

@tvalentyn could you help me to approve running workflows to test my fixes?

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Flink

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Spark

@codecov

codecovBot commented Oct 7, 2022

Copy link
Copy Markdown

Codecov Report

Merging #23546 (08e88a8) into master (9192cb9) will decrease coverage by 0.36%.
The diff coverage is 20.00%.

@@ Coverage Diff @@## master #23546 +/- ##
==========================================
- Coverage 73.46% 73.09% -0.37% 
==========================================
Files 718 729 +11 Lines 95884 98231 +2347 ==========================================
+ Hits 70438 71799 +1361 - Misses 24135 25121 +986 
Partials 1311 1311 
FlagCoverage Δ
python82.36% <20.00%> (-0.86%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted FilesCoverage Δ
sdks/python/apache_beam/testing/test_utils.py90.52% <18.18%> (-9.48%)⬇️
sdks/python/apache_beam/examples/complete/tfidf.py73.43% <25.00%> (-24.95%)⬇️
...python/apache_beam/examples/complete/distribopt.py0.00% <0.00%> (-98.57%)⬇️
...hon/apache_beam/examples/cookbook/mergecontacts.py23.21% <0.00%> (-73.22%)⬇️
...he_beam/examples/cookbook/multiple_output_pardo.py37.50% <0.00%> (-58.34%)⬇️
...python/apache_beam/examples/wordcount_debugging.py38.77% <0.00%> (-57.15%)⬇️
...python/apache_beam/examples/dataframe/wordcount.py38.46% <0.00%> (-53.85%)⬇️
...s/python/apache_beam/examples/wordcount_minimal.py40.74% <0.00%> (-51.86%)⬇️
sdks/python/apache_beam/examples/wordcount.py48.27% <0.00%> (-44.83%)⬇️
...apache_beam/examples/cookbook/custom_ptransform.py52.38% <0.00%> (-42.86%)⬇️
... and 62 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Spark

@benEng

Copy link
Copy Markdown
ContributorAuthor

@tvalentyn I've fixed some of the examples so those can run in Dataflow, but a couple of them are failing https://ci-beam.apache.org/job/beam_PostCommit_Python_Examples_Dataflow_PR/20/ not sure why those are having differences in the assertions, do you have some insight to fix them easily or do you think it is better to sickbay those for the Dataflow suite and fill a new issue?

@benEng

benEng commented Oct 11, 2022

Copy link
Copy Markdown
ContributorAuthor

@tvalentyn

Copy link
Copy Markdown
Contributor

Filing issues and sickbaying sounds good

@tvalentyn

Copy link
Copy Markdown
Contributor

thank you

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Dataflow

@benEng
benEng marked this pull request as ready for review October 12, 2022 21:59
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @TheNeuralBit for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@TheNeuralBitTheNeuralBit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! I have a few suggestions

try:
from apache_beam.io.gcp import gcsio
except ImportError:
gcsio = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this actually protect us? It looks like this would just change the error to a more confusing one: None has no attribure GcsIO, when gcsio is used. I think just letting the ImportError raise would be preferable.

Alternatively we could add a skipIf(gcsio is None), but that might lead to us unintentionally skipping it indefinitely.

logging.info('Creating file: %s', path)
gcs = gcsio.GcsIO()
with gcs.open(path, 'w') as f:
f.write(str.encode(contents, 'utf-8'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I think it would be better if these utilities used the Filesystems API, see here for an example:

defread_csv(path):
withFileSystems.open(path) asfp:
returnpd.read_csv(fp)
result=pd.concat(
read_csv(metadata.path) formetadatainFileSystems.match(
[f'{self.output_path}*'])[0].metadata_list)
result=result.sort_values('Borough').reset_index(drop=True)

It would also be good to extract these out into testing.utils rather than copying them.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks, @TheNeuralBit, I applied some of your suggestions

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Dataflow

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python Examples_Direct

@TheNeuralBit
TheNeuralBit self-requested a review October 20, 2022 21:55
@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @TheNeuralBit

@benEng

Copy link
Copy Markdown
ContributorAuthor

Run Python PreCommit

1 similar comment
@TheNeuralBit

Copy link
Copy Markdown
Member

Run Python PreCommit

@TheNeuralBit

Copy link
Copy Markdown
Member

Run Python 3.8 PostCommit

@TheNeuralBit
TheNeuralBit merged commit c6f64bb into apache:masterNov 1, 2022
@benEng

Copy link
Copy Markdown
ContributorAuthor

Thanks, @TheNeuralBit!

ruslan-ikhsan pushed a commit to akvelon/beam that referenced this pull request Nov 11, 2022
* Fix tests for examples not running in Dataflow
* Remove unused test
* Add todos to enable test for Dataflow
* Refactor utilities functions to create and read files
* Fix lint errors
* Fix lint errors and skip tests that require gcsio and is not available
* Refactor read file function and remove gcsio dependency
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Some test from DataflowExamples suite may not be running on Dataflow.

3 participants

@benEng@tvalentyn@TheNeuralBit