BUG: df.replace over pd.Period columns (#34871)
State: closed

- [x] closes #34871
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

This commit ensures that PeriodArrays return False for _can_hold_element for any element that is not a pd.Period. This prevents upstream code from casting the dtype to object. Also un-xfail test written in #34904

Labels:
name: Bug
name: Period
description: Period data type
name: replace
description: replace method

Comments:
This is my first PR, so I would really appreciate guidance on how to improve the commit, and/or feedback on any process I am not following properly. Thanks in advance
> This is my first PR, so I would really appreciate guidance on how to improve the commit, and/or feedback on any process I am not following properly. Thanks in advance

You're doing well so far.  A couple of comments, then the next thing to do will be to add a note in doc/source/whatsnew/1.2.0.rst giving a short description of the fixed bug
> > This is my first PR, so I would really appreciate guidance on how to improve the commit, and/or feedback on any process I am not following properly. Thanks in advance
> 
> You're doing well so far. A couple of comments, then the next thing to do will be to add a note in doc/source/whatsnew/1.2.0.rst giving a short description of the fixed bug

Thanks for your feedback, addressing your comments now. Also, what is the cause of the build failures? They seem to be happening to everyone, is someone working on fixing them? I was trying to find documentation of the build issue, if it is in fact a widespread thing.
Hello @samc1213! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:





There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2020-11-16 03:22:57 UTC
> Also, what is the cause of the build failures? They seem to be happening to everyone, is someone working on fixing them? 

Yes, don't worry about it (already fixed in fact)
Pardon my ignorance, is there anything else I need to address/do to get this PR pulled? Thanks for all your help @jbrockmendel 
> can u run some asvs (indexing / reshaping ones)
> 
> this could potentially cause some perf issues

Is there a server to run these on? Having issues running these locally in my docker env
> Is there a server to run these on?

No.

> Having issues running these locally in my docker env

are you familiar with using ipython's `%timeit`?
can you merge master
> can you merge master

Will do, sorry I've taken so long on this, haven't had much time to try and get the ASVs working
> also there was a reference in the OP to #35268, if this fixes as well would be great to add the test (if not ok too)

It does not fix #35268 - however, I think it's a very similar code change to fix - I can take care of that once this is approved
> > Is there a server to run these on?
> 
> No.
> 
> > Having issues running these locally in my docker env
> 
> are you familiar with using ipython's `%timeit`?

I think I've got this working, will reply with results shortly
> > > Is there a server to run these on?
> > 
> > 
> > No.
> > > Having issues running these locally in my docker env
> > 
> > 
> > are you familiar with using ipython's `%timeit`?
> 
> I think I've got this working, will reply with results shortly

![image](https://user-images.githubusercontent.com/9583514/97095983-f71dca80-1633-11eb-95db-e091bce00321.png)

Looks like I'm getting some bad results for indexing ASVs. I'm not sure why this is affecting the NumericSeriesIndexing tests, this shouldn't be affecting numeric series?
> Looks like I'm getting some bad results for indexing ASVs. I'm not sure why this is affecting the NumericSeriesIndexing tests, this shouldn't be affecting numeric series?

Unfortunately its not unusual for the asvs to include some noise.  Are these results consistent across runs?  (just re-run the surprising outliers)
> > Looks like I'm getting some bad results for indexing ASVs. I'm not sure why this is affecting the NumericSeriesIndexing tests, this shouldn't be affecting numeric series?
> 
> Unfortunately its not unusual for the asvs to include some noise. Are these results consistent across runs? (just re-run the surprising outliers)

Thanks, looks like I'm making it faster now 😄 

![image](https://user-images.githubusercontent.com/9583514/97385931-27ba6a00-18a9-11eb-926b-597625b60e07.png)

lgtm. @jbrockmendel if you'd look and merge if ok.
cc @jbrockmendel ok here
will take a look this afternoon
One last nitpick, otherwise LGTM, cc @jreback
thanks @samc1213 
@jreback  @jbrockmendel Thanks so much for your patience and feedback, this was a cool experience for me. Hopefully I'll be back! Appreciate all the time you put into this great project