Skip to content

BUG: Allow typecode of 'e' to be passed to select_dtypes #11991

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

jseabold
Copy link
Contributor

@jseabold jseabold commented Jan 7, 2016

Closes #11990.

@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

hmm why does his raise a TypeError? float16 is platform specific I think ?

@jseabold
Copy link
Contributor Author

jseabold commented Jan 7, 2016

np.e is defined and it's a float :)

In [1]: np.e
Out[1]: 2.718281828459045

@@ -1482,10 +1482,11 @@ def _get_dtype_from_object(dtype):

try:
return _get_dtype_from_object(getattr(np,dtype))
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I think this should be changed to:

np.dtype(dtype) as that wontt have the issue, and catch TypeError and not AttributeError

and is more correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On Thu, Jan 7, 2016, 1:09 PM Jeff Reback [email protected] wrote:

In pandas/core/common.py
#11991 (comment):

@@ -1482,10 +1482,11 @@ def _get_dtype_from_object(dtype):

     try:
         return _get_dtype_from_object(getattr(np,dtype))

hmm, I think this should be changed to:

np.dtype(dtype) as that wontt have the issue, and catch TypeError and not
AttributeError

and is more correct

I tried that. There was a test for dtype='integer' that fails. If you think
it shouldn't be supported, I would agree. But I don't feel strongly about
it.

Copy link
Contributor

Choose a reason for hiding this comment

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

how about (just trying to be somewhat generic)

try:
    np.typeDict.get(dtype) or np.typecodes[dtype]``
except KeyError:
    pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would still fail the dtype='integer' case, and I'm not sure the latter would work at all without more processing. It's the use case I'm solving with the test.

What case are you trying to solve with the above?

Copy link
Contributor

Choose a reason for hiding this comment

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

all right, this ok I guess

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Jan 7, 2016
@jreback jreback added this to the 0.18.0 milestone Jan 7, 2016
@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

add a whatsnew note as well

@@ -112,6 +112,7 @@ Other enhancements
values it contains (:issue:`11597`)
- ``Series`` gained an ``is_unique`` attribute (:issue:`11946`)
- ``DataFrame.quantile`` and ``Series.quantile`` now accept ``interpolation`` keyword (:issue:`10174`).
- ``DataFrame.select_dtypes`` now allows the np.float16 typecode (:issue:`11990`)
Copy link
Contributor

Choose a reason for hiding this comment

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

double backticks around np.float16

@jreback
Copy link
Contributor

jreback commented Jan 8, 2016

minor change, pls squash, ping when green.

@jreback
Copy link
Contributor

jreback commented Jan 12, 2016

can you update

TST: Failing test for numpy typecode select

BUG: Let numpy typecodes pass through.

DOC: Document bug fix

STY: Formatting
@jseabold
Copy link
Contributor Author

Green.

@jreback
Copy link
Contributor

jreback commented Jan 12, 2016

I find your patch fine. But isn't this odd?

In [11]: df = DataFrame(np.random.randn(10,2))

In [12]: df[0] = df[0].astype('float16')

In [13]: df.dtypes
Out[13]: 
0    float16
1    float64
dtype: object

In [14]: df.select_dtypes(include=['float'])
Out[14]: 
          1
0 -0.458946
1  0.456845
2  1.246123
3  1.296991
4  1.445800
5  1.082351
6 -0.895652
7  0.031383
8  1.320909
9 -1.783126

In [15]: df.select_dtypes(include=['float16'])
Out[15]: 
          0
0 -0.501465
1  0.623047
2  0.207397
3 -0.251465
4  1.599609
5 -2.359375
6  0.354004
7 -0.191650
8 -1.067383
9 -0.903320

@jreback
Copy link
Contributor

jreback commented Jan 12, 2016

merged via 138b8ba

@jreback jreback closed this Jan 12, 2016
@jseabold jseabold deleted the fix-11990 branch January 13, 2016 00:09
@jseabold
Copy link
Contributor Author

That would be my expectation since np.float64 == np.dtype(float), platform dependent. It's one of the reasons I ran into this, trying to use all float types to capture all eventualities.

@jseabold
Copy link
Contributor Author

Actually, it might be nice to just accept the all typecode aliases too.

On Tue, Jan 12, 2016, 5:48 PM Jeff Reback [email protected] wrote:

Closed #11991 #11991.


Reply to this email directly or view it on GitHub
#11991 (comment).

@jreback
Copy link
Contributor

jreback commented Jan 13, 2016

would accept PR for that addition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants