Skip to content

Csv refactor - #75

Merged
Anna Pavlenko (apavlen) merged 13 commits into
microsoft:mainfrom
bonicim:csv-refactor
Sep 20, 2024
Merged

Anna Pavlenko (apavlen) merged 13 commits into
microsoft:mainfrom
bonicim:csv-refactor

Conversation

@bonicim

Copy link
Copy Markdown
Contributor

Pull Request

Refactor how CSV's are processed (#18)

Add CSV reader utility function; refactor how classes process CSV files


Description

This PR adds a utility function that gets a list of all CSV files ending in perf_event_log given a directory as a Path object. Consequently, it replaces all the duplicate code that processes CSV files with that utility function.


Type of Change

Indicate the type of change by choosing one (or more) of the following:

  • 🛠️ Bug fix
  • 🔄 Refactor
  • 🧪 Tests

Testing

Tests were created for the utility function to handle three cases: 1) CSV files ending in perf_event_log 2) an empty directory and 3) a directory with JSON and CSV files not ending in perf_event_log. Also reran existing tests locally and they passed.


Additional Notes (optional)

Add any additional context or information for reviewers.

@bonicim
Mark Bonicillo (bonicim) requested a review from a team as a code owner September 17, 2024 20:11
@bonicim Mark Bonicillo (bonicim) changed the title Csv refactor Draft: Csv refactor Sep 17, 2024
@bonicim

Copy link
Copy Markdown
Contributor Author

Karla Saur (@ksaur) This is a draft for early feedback on my solution. I will fix the merge conflicts and rebase my branch to main later today.

@ksaur

Copy link
Copy Markdown
Contributor

Karla Saur (@ksaur) This is a draft for early feedback on my solution. I will fix the merge conflicts and rebase my branch to main later today.

Yes this is what we need, thank you! :)

@bonicim

Copy link
Copy Markdown
Contributor Author

Mark Bonicillo (@bonicim) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@bonicim Mark Bonicillo (bonicim) changed the title Draft: Csv refactor Csv refactor Sep 18, 2024
@bonicim

Copy link
Copy Markdown
Contributor Author

Karla Saur (@ksaur) Finally rebased main and refactored my commons module to fit with the new structure. Reran all tests locally.

except Exception as e:
self.logger.error(f"Error reading {path} {e}")
continue
try:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since the utility function list_perf_event_log_files already checks for files that end in perf_event_log, this check (i.e. if statement) is redundant and no longer needed.

csv_paths = list(self.data_dir.glob("**/*.csv"))
if csv_paths == []:
csv_paths = list_perf_event_log_files(self.data_dir)
if not csv_paths:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit. Changed the if statement to be more pythonic (i.e. empty lists are considered False).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. FWIW, a handful of these got fixed in #85. I think if you merge main in you should see them get updated.

We also setup black formatting to handle some other items.

You could try to following to rebase your changes:

# get the latest configs from uptsream
git remote add upstream https://github.com/microsoft/vasim
git fetch upstream
git restore --source=upstream/main pyproject.toml setup.py .pre-commit-config.yaml

# get the new deps
pip install -U -e ".[dev]"

# reformat the files
isort .
black .
pydocstringformatter .
git commit -a -m "reformatting"

# now try and merge main and handle the hopefully smaller set of conflicts
git merge upstream/main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also, if you want one of us can tackle this part ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Brian Kroth (@bpkroth) Just read your comment. Thanks for the git commands; they make sense. I'll use them to set up my dev environment so that future PR's can catch any quality checks early and locally.

raise FileNotFoundError(f'Error reading csvs from {self.data_dir}. Your csv_paths are empty.')

# Process data
# Read all data from file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moving this comment further down to the line of code that I think where scale becomes an issue. Also created a new issue in GitHub to track this: #93

Comment thread tests/test_commons/test_utils.py Resolved

@ksaur Karla Saur (ksaur) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks so much for this PR, it will really help the users since the CSV stuff is the easiest thing to screw up! I think there is a license header that is missing, but once you pass the CI you are good to merge!

@apavlen Anna Pavlenko (apavlen) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! please rebase and you might need to fix a few issues for merged linters (adding headers, maybe formatters)

Comment thread src/vasim/commons/utils.py Resolved
self.logger.error('Error: no csvs found in data_dir {}'.format(self.data_dir))
raise SystemExit('Error: no csvs found in data_dir {}'.format(self.data_dir))
if not list_perf_event_log_files(self.data_dir):
err_msg = f'Error: no csvs found in data_dir {self.data_dir}'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might fail with new linter rule of using %s format for logging instead of f-strings

Comment thread tests/test_commons/test_utils.py Resolved
@bonicim

Copy link
Copy Markdown
Contributor Author

Thanks so much for this PR, it will really help the users since the CSV stuff is the easiest thing to screw up! I think there is a license header that is missing, but once you pass the CI you are good to merge!

Karla Saur (@ksaur) Looks like that I don't have permissions to merge PR's. Moreover, could you approve the workflows?

@apavlen

Copy link
Copy Markdown
Contributor

The checks are failings with pylint formatting errors. Most likely you committed your changes before pre-commit hooks were pushed, so you didn't see warnings locally, but now it fails your build on GitHub. Can you please check output and update?

@ksaur

Karla Saur (ksaur) commented Sep 20, 2024 •

Copy link
Copy Markdown
Contributor

let me see if there is a setting to approve the workflows so you can run them yourself, sorry about that!
[update] I think i fixed it

@jcamachor

Copy link
Copy Markdown
Contributor

let me see if there is a setting to approve the workflows so you can run them yourself, sorry about that!

Karla Saur (@ksaur) , the current setup is that they run automatically after first contribution.

@bpkroth

Copy link
Copy Markdown
Contributor

The checks are failings with pylint formatting errors. Most likely you committed your changes before pre-commit hooks were pushed, so you didn't see warnings locally, but now it fails your build on GitHub. Can you please check output and update?

Since changes were committed prior to merge that included those updated checks, you might also have to run the full suite like so:

pre-commit run -a

Apologies for the extra steps. You started before we'd incorporated some of these. It should be easier/better in the future though.

Let us know if you want help at all. Happy to take a stab at it.

@bpkroth

Copy link
Copy Markdown
Contributor

The checks are failings with pylint formatting errors. Most likely you committed your changes before pre-commit hooks were pushed, so you didn't see warnings locally, but now it fails your build on GitHub. Can you please check output and update?

Since changes were committed prior to merge that included those updated checks, you might also have to run the full suite like so:

pre-commit run -a

Apologies for the extra steps. You started before we'd incorporated some of these. It should be easier/better in the future though.

Let us know if you want help at all. Happy to take a stab at it.

Mark Bonicillo (@bonicim) I tackled these for you. They were pretty minor.

Karla Saur (@ksaur), Anna Pavlenko (@apavlen) I think this should be ready to merge now.

@apavlen
Anna Pavlenko (apavlen) merged commit d2e5f5b into microsoft:main Sep 20, 2024
@bonicim

Copy link
Copy Markdown
Contributor Author

The checks are failings with pylint formatting errors. Most likely you committed your changes before pre-commit hooks were pushed, so you didn't see warnings locally, but now it fails your build on GitHub. Can you please check output and update?

Since changes were committed prior to merge that included those updated checks, you might also have to run the full suite like so:

pre-commit run -a

Apologies for the extra steps. You started before we'd incorporated some of these. It should be easier/better in the future though.
Let us know if you want help at all. Happy to take a stab at it.

Mark Bonicillo (@bonicim) I tackled these for you. They were pretty minor.

Karla Saur (@ksaur), Anna Pavlenko (@apavlen) I think this should be ready to merge now.

thanks, Brian Kroth (@bpkroth). I would have fixed this myself, but I was stuck in meetings all this morning (East coast time). Appreciate the assist.

@bonicim
Mark Bonicillo (bonicim) deleted the csv-refactor branch September 20, 2024 18:44
@bpkroth

Copy link
Copy Markdown
Contributor

The checks are failings with pylint formatting errors. Most likely you committed your changes before pre-commit hooks were pushed, so you didn't see warnings locally, but now it fails your build on GitHub. Can you please check output and update?

Since changes were committed prior to merge that included those updated checks, you might also have to run the full suite like so:

pre-commit run -a

Apologies for the extra steps. You started before we'd incorporated some of these. It should be easier/better in the future though.
Let us know if you want help at all. Happy to take a stab at it.

Mark Bonicillo (@bonicim) I tackled these for you. They were pretty minor.
Karla Saur (@ksaur), Anna Pavlenko (@apavlen) I think this should be ready to merge now.

thanks, Brian Kroth (@bpkroth). I would have fixed this myself, but I was stuck in meetings all this morning (East coast time). Appreciate the assist.

No problem. Partially my fault for pushing all the coding practice stuff so I figure I can pitch in to help fix it.

Thanks for your contribution!

Cheers,
Brian

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.

5 participants