Skip to content
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: replace coerces incorrect dtype #12780

Closed
wants to merge 3 commits into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Apr 3, 2016

@sinhrks sinhrks added Bug Dtype Conversions Unexpected or buggy dtype conversions API Design labels Apr 3, 2016
@sinhrks sinhrks added this to the 0.18.1 milestone Apr 3, 2016
@sinhrks sinhrks force-pushed the replace_type branch 2 times, most recently from 8ca4b9a to df2eae1 Compare April 3, 2016 15:55
@@ -1355,6 +1365,12 @@ class NumericBlock(Block):
is_numeric = True
_can_hold_na = True

def _can_replace_element(self, element):
# coercion is handled by putmask

Copy link
Contributor

Choose a reason for hiding this comment

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

no

In [1]: issubclass(np.bool_, np.number)
Out[1]: False

In [2]: issubclass(np.float_, np.number)
Out[2]: True

@sinhrks sinhrks force-pushed the replace_type branch 3 times, most recently from 72d13eb to 0c7f4de Compare April 4, 2016 16:36
@sinhrks
Copy link
Member Author

sinhrks commented Apr 6, 2016

Found this affects more functions than I thought. Let me do it in 4 separate PRs.

1 Add numeric related tests to clarify the current behaviour (and future change)
2. Fix numeric coercion.
3. Add datetime-like tests.
4. Fix datetime-like coercion.

@sinhrks sinhrks mentioned this pull request Apr 9, 2016
3 tasks
jreback pushed a commit that referenced this pull request Apr 10, 2016
related to #12747 and #12780

Author: sinhrks <sinhrks@gmail.com>

Closes #12841 from sinhrks/dtype_tests and squashes the following commits:

e11cc2a [sinhrks] TST: Add numeric coercion tests
@sinhrks sinhrks modified the milestones: 0.19.0, 0.18.1 Apr 10, 2016
@codecov-io
Copy link

codecov-io commented May 13, 2016

Current coverage is 85.97% (diff: 89.65%)

Merging #12780 into master will decrease coverage by <.01%

@@             master     #12780   diff @@
==========================================
  Files           140        140          
  Lines         51254      51275    +21   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          44068      44085    +17   
- Misses         7186       7190     +4   
  Partials          0          0          

Powered by Codecov. Last update a62fdf8...f9154e8

@jreback
Copy link
Contributor

jreback commented May 13, 2016

after #13147 this should be slightly more standard


def _assert_replace_conversion(self, from_key, to_key, how):
index = pd.Index([3, 4], name='xxx')
obj = pd.Series(self.rep[from_key], index=index, name='yyy')
self.assertEqual(obj.dtype, from_key)

if (from_key.startswith('datetime') and to_key.startswith('datetime')):
# different tz, currently mask_missing raises SystemError
Copy link
Contributor

Choose a reason for hiding this comment

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

is this for another issue?

Copy link
Member Author

@sinhrks sinhrks Jan 21, 2017

Choose a reason for hiding this comment

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

Yeah, issued #15183. Let me fix it in a separate pr.

@jreback
Copy link
Contributor

jreback commented Nov 23, 2016

@sinhrks looks pretty good, just a couple of small comments.

@@ -3233,6 +3236,16 @@ def comp(s):
return _possibly_compare(values, getattr(s, 'asm8', s),
operator.eq)

def _cast(block, scalar):
Copy link
Contributor

Choose a reason for hiding this comment

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

this might be a more general routine (IOW maybe defin as a utility function in internals rather than a nested function here), or maybe as a block method?

cast_scalar?

@jreback
Copy link
Contributor

jreback commented Jan 19, 2017

@sinhrks status? (lgtm so far)

@sinhrks sinhrks changed the title (WIP)BUG: replace coerces incorrect dtype BUG: replace coerces incorrect dtype Jan 21, 2017
@sinhrks
Copy link
Member Author

sinhrks commented Jan 21, 2017

Updated to fix the above points, and now ready for review.

@jreback jreback added this to the 0.20.0 milestone Jan 21, 2017
@jreback
Copy link
Contributor

jreback commented Jan 21, 2017

looks fine. still some internal things ideally should clean up. but can do later.

though couple of comments if you can address.

@@ -361,6 +377,11 @@ def _infer_dtype_from_scalar(val):
elif is_complex(val):
dtype = np.complex_

elif pandas_dtype:
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this parameter necessary, why wouldn't we always want to infer a pandas dtype if its there (e.g. Period)?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not needed for the PR itself. The same func is required for #14145.

if val is tslib.NaT or val.tz is None:
dtype = np.dtype('M8[ns]')
else:
if pandas_dtype:
Copy link
Contributor

Choose a reason for hiding this comment

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

e.g. here, is this a back-compat issue?

@jreback
Copy link
Contributor

jreback commented Mar 20, 2017

@sinhrks I am rebasing this and will merge after testing.

jreback pushed a commit to jreback/pandas that referenced this pull request Mar 20, 2017
closes pandas-dev#12747

Author: sinhrks <sinhrks@gmail.com>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <jeff@reback.net>

Closes pandas-dev#12780 from sinhrks/replace_type and squashes the following commits:

f9154e8 [sinhrks] remove unnecessary comments
279fdf6 [sinhrks] remove import failure
de44877 [sinhrks] BUG: replace coerces incorrect dtype
@jreback jreback closed this Mar 20, 2017
jreback added a commit that referenced this pull request Mar 21, 2017
xref #15736   xref #12780

Author: Jeff Reback <jeff@reback.net>

Closes #15765 from jreback/common_types and squashes the following commits:

d472646 [Jeff Reback] try removing restriction on windows
8d07cae [Jeff Reback] CLN: replace _interleave_dtype with _find_common_type
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
closes pandas-dev#12747

Author: sinhrks <sinhrks@gmail.com>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <jeff@reback.net>

Closes pandas-dev#12780 from sinhrks/replace_type and squashes the following commits:

f9154e8 [sinhrks] remove unnecessary comments
279fdf6 [sinhrks] remove import failure
de44877 [sinhrks] BUG: replace coerces incorrect dtype
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
xref pandas-dev#15736   xref pandas-dev#12780

Author: Jeff Reback <jeff@reback.net>

Closes pandas-dev#15765 from jreback/common_types and squashes the following commits:

d472646 [Jeff Reback] try removing restriction on windows
8d07cae [Jeff Reback] CLN: replace _interleave_dtype with _find_common_type
mattip pushed a commit to mattip/pandas that referenced this pull request Apr 3, 2017
closes pandas-dev#12747

Author: sinhrks <sinhrks@gmail.com>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <jeff@reback.net>

Closes pandas-dev#12780 from sinhrks/replace_type and squashes the following commits:

f9154e8 [sinhrks] remove unnecessary comments
279fdf6 [sinhrks] remove import failure
de44877 [sinhrks] BUG: replace coerces incorrect dtype
mattip pushed a commit to mattip/pandas that referenced this pull request Apr 3, 2017
xref pandas-dev#15736   xref pandas-dev#12780

Author: Jeff Reback <jeff@reback.net>

Closes pandas-dev#15765 from jreback/common_types and squashes the following commits:

d472646 [Jeff Reback] try removing restriction on windows
8d07cae [Jeff Reback] CLN: replace _interleave_dtype with _find_common_type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG/API: Fix .replace dtype conversion rules
4 participants