Skip to content

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

Merged
merged 2 commits into from
Apr 24, 2018
Merged

Conversation

datapythonista
Copy link
Member

  • closes str.get fails if Series contains dict #20671
  • tests added / passed (* unrelated tests failed, with locale problems, not sure if caused by something on my system or something on pandas)
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@@ -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`)
Copy link
Contributor

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)

@@ -2568,6 +2568,16 @@ def test_get(self):
expected = Series(['3', '8', np.nan])
tm.assert_series_equal(result, expected)

# complex structures
Copy link
Contributor

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

@@ -2568,6 +2568,16 @@ def test_get(self):
expected = Series(['3', '8', np.nan])
tm.assert_series_equal(result, expected)

# complex structures
Copy link
Contributor

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

expected = Series([2, 2, np.nan, 'a'])

result = values.str.get(-1)
expected = Series([3, 3, np.nan, np.nan])
Copy link
Contributor

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)

Copy link
Member Author

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.

@jreback jreback added Bug Strings String extension data type and string data labels Apr 14, 2018
@jreback
Copy link
Contributor

jreback commented Apr 14, 2018

also can you review the doc-string for correctness for this case (add an example if you can as well)

@datapythonista
Copy link
Member Author

We're reviewing the docstring and adding the example in #20667.

expected = Series([3, 3, np.nan, np.nan])
tm.assert_series_equal(result, expected)

for to_type in tuple, list, np.array:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you parameterize this

Copy link
Member Author

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

Copy link
Contributor

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):
   ...

Copy link
Member Author

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.

@jreback jreback added this to the 0.23.0 milestone Apr 24, 2018
@jreback jreback merged commit efabfc8 into pandas-dev:master Apr 24, 2018
@jreback
Copy link
Contributor

jreback commented Apr 24, 2018

thanks @datapythonista

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

str.get fails if Series contains dict
2 participants