-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Fixed exception when Series.str.get is used with dict values and the index is not an existing key (#20671) #20672
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: Fixed exception when Series.str.get is used with dict values and the index is not an existing key (#20671) #20672
Conversation
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -1175,3 +1175,4 @@ Other | |||
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`) | |||
- Bug in accessing a :func:`pandas.get_option`, which raised ``KeyError`` rather than ``OptionError`` when looking up a non-existant option key in some cases (:issue:`19789`) | |||
- Bug in :func:`assert_series_equal` and :func:`assert_frame_equal` for Series or DataFrames with differing unicode data (:issue:`20503`) | |||
- Bug in :func:`Series.str.get` with a dictionary in the values and the index not in the keys, raising `KeyError` (:issue:`20671`) |
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 you make a sub-section 'Strings' under Numeric (and move there)
pandas/tests/test_strings.py
Outdated
@@ -2568,6 +2568,16 @@ def test_get(self): | |||
expected = Series(['3', '8', np.nan]) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
# complex structures |
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.
change comment to dict; add the gh issue as a reference
pandas/tests/test_strings.py
Outdated
@@ -2568,6 +2568,16 @@ def test_get(self): | |||
expected = Series(['3', '8', np.nan]) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
# complex structures |
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 make this a new test_get_complex
pandas/tests/test_strings.py
Outdated
expected = Series([2, 2, np.nan, 'a']) | ||
|
||
result = values.str.get(-1) | ||
expected = Series([3, 3, np.nan, np.nan]) |
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 .get for embedded lists/tuples/ndarrays (you may want to parameterize)
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.
Not 100% if by embedded you meant nested, let me know if what I implemented is not what you meant.
also can you review the doc-string for correctness for this case (add an example if you can as well) |
… the index is not an existing key (#20671)
We're reviewing the docstring and adding the example in #20667. |
pandas/tests/test_strings.py
Outdated
expected = Series([3, 3, np.nan, np.nan]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
for to_type in tuple, list, np.array: |
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 parameterize this
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.
not sure what do you mean by parametrize, sorry
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.
http://pandas-docs.github.io/pandas-docs-travis/contributing.html#using-pytest
something like
pytest.mark.parametrize("box", [tuple, list, np.array]):
def test.....(box):
...
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.
Didn't used that before, thanks for the clarification. Updated.
thanks @datapythonista |
git diff upstream/master -u -- "*.py" | flake8 --diff