Skip to content

BUG: .rename* not treating Series as mapping #12626

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

Closed
wants to merge 1 commit into from

Conversation

TomAugspurger
Copy link
Contributor

Closes #12623

I added com.is_dict_like in #11980
and failed to use it for the rename method. Using that now and did
some refactoring while I was in there. Added more tests for rename.

@TomAugspurger
Copy link
Contributor Author

I might remove or rename core._is_scalar_or_list_like. It doesn't seem like a well-defined or clear check...

@jreback
Copy link
Contributor

jreback commented Mar 14, 2016

@TomAugspurger btw, make sure you are rebased on current master. dateutil=2.5.0 flowed thru and broke some tests and I just fixed in (maybe 2 hrs ago)

(not com.is_sequence(index) and not callable(index)) or
(com.is_list_like(index) and not isinstance(index, MutableMapping))
)
if is_scalar_or_list:
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think lib.isscalar(...) or com.is_list_like(...) is more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

com.is_list_like(dict) is True, and I need to treat dicts differently than lists.

But if we're going to be raising on Series.rename(list) anway, I won't have to worry about lists at all...

@jreback jreback added the Bug label Mar 14, 2016
@jreback jreback added this to the 0.18.1 milestone Mar 14, 2016
@@ -55,6 +55,13 @@ def test_rename(self):
renamed = renamer.rename({})
self.assertEqual(renamed.index.name, renamer.index.name)

def test_rename_by_series(self):
s = Series(range(5), name='foo')
renamer = Series({1: 10, 2: 20})
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe tests both dict and Series (for the renamer), and anything else that could be there (e.g. callable)? you prob already have these tests......

d = {1: 10, 2: 20}
for value in [ d, Series(d) ]:
     ....

for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These should all covered by test_generic now. Initially I didn't understand how test_generic was setup, so I added the test here. I think these tests are all redundant, and could remove them this one and test_rename above, but I always worry about deleting tests :)

Copy link
Contributor

Choose a reason for hiding this comment

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

cool np. yeah. hard to stop the propogation of tests :)

Closes pandas-dev#12623

I added com.is_dict_like in pandas-dev#11980
and failed to use it for the `rename` method. Using that now and did
some refactoring while I was in there. Added more tests for rename.
@TomAugspurger
Copy link
Contributor Author

Ok, the tests for the different possible arguments are here. I simplified the stuff with is_scalar_or_mapping to just do the check in the code. Should be clearer now, but a bit less DRY.

@jreback jreback closed this in b0d1e2a Mar 17, 2016
@jreback
Copy link
Contributor

jreback commented Mar 17, 2016

thanks @TomAugspurger

@TomAugspurger TomAugspurger deleted the rename-series branch April 5, 2017 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants