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

Converts statcast over to using the try_parse code that autodetermines data types #106

Merged
merged 11 commits into from
Sep 8, 2020

Conversation

TheCleric
Copy link
Contributor

This PR was done in three steps:

  1. Create unit tests for existing statcast code
  2. Migrate statcast to using the try_parse postprocessor to autodetermine data types
  3. Ensure unit tests run successfully

When merged this PR should fix the following issues: #105, #104, #59

'%Y-%m-%dT%H:%M:%S.%fZ', # Just in case (https://github.com/jldbc/pybaseball/issues/104)
]

def try_parse_dataframe(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this fit on one line? Maybe by setting something for Unon[str, int, float', datetime']?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Define ColType = Union[str, int, float', datetime'] somewhere, and annotate ColType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you find it less readable on multiple lines? I'll put it on one line if desired, but I find it more readable this way. You near instantly can see how many parameters it takes, of what type, and which have defaults. Whereas one one line they tend to somewhat run together in my opinion.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also digging through the PEP to see what are the preferred way to handle this and found this discussion:

python/typing#433

Where they suggested an alternative that would look like this if you'd prefer (though I personally find it less readable):

def try_parse_dataframe(data: pd.DataFrame, null_replacement: Union[str, int, float, datetime] = np.nan,
                        known_percentages: List[str] = []) -> pd.DataFrame:

@schorrm
Copy link
Collaborator

schorrm commented Sep 8, 2020

LGTM

@schorrm schorrm merged commit f45c4ca into jldbc:master Sep 8, 2020
@TheCleric TheCleric deleted the feature/statcast_use_try_parse branch September 11, 2020 14:14
schorrm pushed a commit that referenced this pull request Sep 18, 2020
…s data types (#106)

* Add unit tests for statcast to ensure backwards compatibility

* Convert statcast to using try_parse

* Add some missing testing
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.

None yet

2 participants