-
-
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
BUG: Set index when reading stata file #17328
Conversation
pandas/io/stata.py
Outdated
@@ -1486,6 +1486,8 @@ def read(self, nrows=None, convert_dates=None, | |||
columns = self._columns | |||
if order_categoricals is None: | |||
order_categoricals = self._order_categoricals | |||
if index is None: | |||
index = self._index |
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.
Do we have tests that hit this path?
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.
Added in PR
Codecov Report
@@ Coverage Diff @@
## master #17328 +/- ##
==========================================
+ Coverage 91.01% 91.02% +<.01%
==========================================
Files 162 162
Lines 49567 49571 +4
==========================================
+ Hits 45113 45120 +7
+ Misses 4454 4451 -3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17328 +/- ##
==========================================
+ Coverage 91.01% 91.02% +<.01%
==========================================
Files 162 162
Lines 49567 49571 +4
==========================================
+ Hits 45113 45120 +7
+ Misses 4454 4451 -3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17328 +/- ##
==========================================
- Coverage 91.01% 90.99% -0.02%
==========================================
Files 163 163
Lines 49567 49575 +8
==========================================
- Hits 45113 45112 -1
- Misses 4454 4463 +9
Continue to review full report at Codecov.
|
Did we want to change the keyword from |
Probably a good idea. |
Does this need deprecation? |
Last one, is there a pattern to follow for renaming (e.g. a decorator, *kwargs, etc) |
Yeah, there's an |
It's in |
b8e36ac
to
dd83e7b
Compare
I went ahead and did the insta-deprecate. |
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.
minor comments. can you deprecate index
(and direct to index_col
) as well.
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -293,6 +293,7 @@ Other API Changes | |||
- :func:`Series.argmin` and :func:`Series.argmax` will now raise a ``TypeError`` when used with ``object`` dtypes, instead of a ``ValueError`` (:issue:`13595`) | |||
- :class:`Period` is now immutable, and will now raise an ``AttributeError`` when a user tries to assign a new value to the ``ordinal`` or ``freq`` attributes (:issue:`17116`). | |||
- :func:`to_datetime` when passed a tz-aware ``origin=`` kwarg will now raise a more informative ``ValueError`` rather than a ``TypeError`` (:issue:`16842`) | |||
- Renamed non-functional `index` to `index_col` in :func:`read_stata` to improve API consistency (:issue:`16342`) |
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.
can you use double backticks here (around index,index_col)
pandas/tests/io/test_stata.py
Outdated
@@ -1309,3 +1309,11 @@ def test_value_labels_iterator(self, write_index): | |||
dta_iter = pd.read_stata(path, iterator=True) | |||
value_labels = dta_iter.value_labels() | |||
assert value_labels == {'A': {0: 'A', 1: 'B', 2: 'C', 3: 'E'}} | |||
|
|||
def test_set_index(self): | |||
df = tm.makeDataFrame() |
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.
can you add the issue number
Ensures index is set when requested during reading of a Stata dta file Deprecates and renames index to index_col for API consistence closes pandas-dev#16342
dd83e7b
to
4e30df8
Compare
Do we need a deprecation, or can we just "break" API here. |
Ahh I see 4e30df8 now so nevermind, that's fine. |
@jreback @TomAugspurger I think this is GTG |
Thanks! |
Ensures index is set when requested during reading of a Stata dta file Deprecates and renames index to index_col for API consistence closes pandas-dev#16342
Ensures index is set when requested during reading of a Stata dta file Deprecates and renames index to index_col for API consistence closes pandas-dev#16342
Ensures index is set when requested when reading state dta file
closes #16342
index
parameter #16342git diff upstream/master -u -- "*.py" | flake8 --diff