-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
CLN/MAINT: Clean and annotate stata reader and writers #31072
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bashtage. Nice! generally lgtm.
We have a Label
alias in pandas._typing which I think you could use in several places.
also Union[float, int] is equivalent to just float for typing purposes. My preference is to do this, but others may disagree.
Thanks @simonjayhawkins . I've hit a roadblock with the errors below. Is there anything that can be done about them?
|
3780cbe
to
2b288df
Compare
I'll pull this locally and have a look in a bit. |
pandas/core/frame.py
Outdated
if version == 114 and convert_strl is not None: | ||
raise ValueError("strl is not supported in format 114") | ||
|
||
# TODO: There must be a better way? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a # type: ignore
would be reasonable here. just add the mypy error (error: Name 'statawriter' already defined (possibly by an import)
) as a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an alternate since they all inherit from statawriter would be to declare something like writer: StataWriter
before the if...else blocks and assign to that within blocks
No strong preference either way. The current method is wordier but on the plus side highlights the differences in arguments between each, which isn't bad either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've ignored for now and reverted this. I can always go back to the wordier version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think typing writer as StataWriter doesn't work since the different flavors accept different arguments, which triggers a warning. I should fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...but fixing it would change the API and so I better not.
e0f5268
to
eabce9f
Compare
Any idea how the final block can be typed? Or should I just remove the typing information from this function? |
|
I think the mypy issues are a result of the arithmetic ops for pandas objects being defined at runtime and not statically. I opened #31160 to track As far as this PR is concerned I would remove annotations from those functions or |
8408a88
to
4fcbe33
Compare
All green now. I requested a rereview to see if this can get across the line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bashtage lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm @jreback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. needs a rebase and can merge on green.
Ensure all pytest raises are not bare
cbe52f5
to
d6f2278
Compare
Add type annotations in Stata General clean up Fix one small bug using in rather than == Use method to write data
@jreback Green. I squashed to two distinct commits, one for the typing and one for the final bare pytest raises. |
thanks @bashtage very nice! |
great, though when we merge it gets squashed to one :-> (but history is preserved on this PR) |
…ndexing-1row-df * upstream/master: (194 commits) DOC Remove Python 2 specific comments from documentation (pandas-dev#31198) Follow up PR: pandas-dev#28097 Simplify branch statement (pandas-dev#29243) BUG: DatetimeIndex.snap incorrectly setting freq (pandas-dev#31188) Move DataFrame.info() to live with similar functions (pandas-dev#31317) ENH: accept a dictionary in plot colors (pandas-dev#31071) PERF: add shortcut to Timestamp constructor (pandas-dev#30676) CLN/MAINT: Clean and annotate stata reader and writers (pandas-dev#31072) REF: define _get_slice_axis in correct classes (pandas-dev#31304) BUG: DataFrame.floordiv(ser, axis=0) not matching column-wise bheavior (pandas-dev#31271) PERF: optimize is_scalar, is_iterator (pandas-dev#31294) BUG: Series rolling count ignores min_periods (pandas-dev#30923) xfail sparse warning; closes pandas-dev#31310 (pandas-dev#31311) REF: DatetimeIndex.get_value wrap DTI.get_loc (pandas-dev#31314) CLN: internals.managers (pandas-dev#31316) PERF: avoid copies if possible in fill_binop (pandas-dev#31300) Add test for multiindex json (pandas-dev#31307) BUG: passing TDA and wrong freq to TimedeltaIndex (pandas-dev#31268) BUG: inconsistency between PeriodIndex.get_value vs get_loc (pandas-dev#31172) CLN: remove _set_subtyp (pandas-dev#31301) CI: Updated version of macos image (pandas-dev#31292) ...
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff