Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
CLN: Make ufunc works for Index #10638
Conversation
|
yep I think you could take them out. as |
jreback
added the
Clean
label
Jul 20, 2015
|
No, we need this. Otherwise It's not documented, but |
|
ok let's add some tests and clean up the code eg to support the example above |
|
IIRC there is another issue where for example (#9966 with a PR #9974) :
which is wrong, this needs to be created w/o slightly differently, e.g.
so that the attributes get propogates AND the correct type gets inferred (e.g. this would return a maybe you want to supersede #9974 |
|
Thanks. I'll fix https://github.com/pydata/pandas/blob/master/pandas/core/index.py#L253 Am I correct that defining http://docs.scipy.org/doc/numpy/reference/arrays.classes.html |
|
This is correct -- array_wraps is what we need. On Tue, Jul 21, 2015 at 5:44 AM, Sinhrks notifications@github.com wrote:
|
sinhrks
changed the title from
CLN: Remote Datetime-like Index.__array_finalize__ to CLN: Remove Datetime-like Index.__array_finalize__
Jul 22, 2015
|
Let me confirm 2 points:
|
|
@sinhrks both of those points look right |
jreback
added this to the
0.17.0
milestone
Jul 23, 2015
jreback
added Indexing Dtypes
labels
Jul 23, 2015
|
Yes, agreed On Thu, Jul 23, 2015 at 4:14 AM, jreback notifications@github.com wrote:
|
jreback
commented on the diff
Jul 23, 2015
| @@ -281,6 +281,16 @@ def __contains__(self, key): | ||
| return False | ||
| return key.ordinal in self._engine | ||
| + def __array_wrap__(self, result, context=None): |
jreback
Contributor
|
MaximilianR
referenced
this pull request
Jul 23, 2015
Closed
Drop & insert on subtypes of index return their subtypes #10620
sinhrks
changed the title from
CLN: Remove Datetime-like Index.__array_finalize__ to CLN: Make ufunc works for Index
Jul 23, 2015
sinhrks
referenced
this pull request
Aug 1, 2015
Merged
BUG: PeriodIndex.order doesnt preserve freq #10305
jreback
referenced
this pull request
Aug 5, 2015
Closed
Change of index values dtype should be reflected in index type #9974
|
@sinhrks how's this coming along? |
|
@sinhrks how's this coming? |
|
@sinhrks if you can get to this in the next couple of days gr8, otherwise will defer this. |
|
I've looked through |
|
@sinhrks I think |
|
@jreback Thanks, will check this. |
sinhrks
and 2 others
commented on an outdated diff
Sep 1, 2015
| @@ -306,6 +307,23 @@ def __contains__(self, key): | ||
| return False | ||
| return key.ordinal in self._engine | ||
| + def __array_wrap__(self, result, context=None): | ||
| + """ | ||
| + Gets called after a ufunc. Needs additional handling as | ||
| + PeriodIndex stores internal data as int dtype | ||
| + """ | ||
| + if isinstance(context, tuple) and len(context) > 0: | ||
| + func = context[0] | ||
| + if (func is np.add): | ||
| + return self._add_delta(context[1][1]) | ||
| + elif (func is np.subtract): | ||
| + return self._add_delta(-context[1][1]) | ||
| + elif isinstance(func, np.ufunc): | ||
| + if 'M->M' not in func.types: | ||
| + msg = "ufunc '{0}' not supported for the PeriodIndex" | ||
| + raise ValueError(msg.format(func.__name__)) |
sinhrks
Member
|
|
Updated and now green. |
jreback
commented on the diff
Sep 5, 2015
| + def test_numpy_ufuncs(self): | ||
| + # test ufuncs of numpy 1.9.2. see: | ||
| + # http://docs.scipy.org/doc/numpy/reference/ufuncs.html | ||
| + | ||
| + # some functions are skipped because it may return different result | ||
| + # for unicode input depending on numpy version | ||
| + | ||
| + for name, idx in compat.iteritems(self.indices): | ||
| + for func in [np.exp, np.exp2, np.expm1, np.log, np.log2, np.log10, | ||
| + np.log1p, np.sqrt, np.sin, np.cos, | ||
| + np.tan, np.arcsin, np.arccos, np.arctan, | ||
| + np.sinh, np.cosh, np.tanh, np.arcsinh, np.arccosh, | ||
| + np.arctanh, np.deg2rad, np.rad2deg]: | ||
| + if isinstance(idx, pd.tseries.base.DatetimeIndexOpsMixin): | ||
| + # raise TypeError or ValueError (PeriodIndex) | ||
| + # PeriodIndex behavior should be changed in future version |
sinhrks
Member
|
|
this doesn't seeem to close #9966 ?
|
|
@jreback Standard arithmetic is handled by
|
|
Failed in
|
|
@sinhrks hmm I think you need to set the |
jreback
added a commit
that referenced
this pull request
Sep 6, 2015
|
|
jreback |
0cacd24
|
jreback
merged commit 0cacd24
into pandas-dev:master
Sep 6, 2015
1 check passed
|
@sinhrks thanks! |
sinhrks commentedJul 20, 2015
closes #9966, #9974 (PR)
I understand these are never used because
Indexis no longer the subclass ofnp.array. Correct?allalmost ufuncsCategoricalIndex: Needs to be done separately to fixCategorical, because number of categories can be changed.TypeErrororAttributeError, as ufuncs are performed to array of tuples.