Skip to content

Numindexname #13205

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 6 commits into from
Closed

Numindexname #13205

wants to merge 6 commits into from

Conversation

toobaz
Copy link
Member

@toobaz toobaz commented May 17, 2016

This is a rebased & updated version of #12331

I would say the last commit is the most critical one: it exposes the consequences of making numeric indices only support their default dtype. By the way: I had interpreted your comment as "raise if dtype is set", but I don't think this is what we want, since it breaks the obj -> str(obj) -> obj roundtrip. So I raise only if dtype is not the expected dtype.

expected = Index(i.values.astype(dtype))
tm.assert_index_equal(result, expected)
i = Float64Index([0, 1, 2])
result = i.astype('int64')
Copy link
Contributor

Choose a reason for hiding this comment

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

you can't change this. a float32 should simply be promoted to float64 (and likewise int32 to int64)

Copy link
Member Author

Choose a reason for hiding this comment

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

(right, fixed)

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Compat pandas objects compatability with Numpy or Python functions labels May 17, 2016
if name is None and hasattr(levels, 'name'):
name = levels.name
if isinstance(levels, MultiIndex):
return levels.copy(name=name, names=names, deep=copy)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this needed for? passing a levels multi-index is very odd

Copy link
Member Author

Choose a reason for hiding this comment

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

I assumed we want idx.__class__(idx) to return a copy of idx for any index idx. But maybe it was just my fantasy...

Copy link
Contributor

Choose a reason for hiding this comment

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

well did you test this? if this were to be supported then it should be the very first check.

I am not averse (and other Indexes do this), but needs testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is tested here

@codecov-io
Copy link

codecov-io commented May 17, 2016

Current coverage is 84.25%

Merging #13205 into master will increase coverage by 0.01%

@@             master     #13205   diff @@
==========================================
  Files           138        138          
  Lines         50805      50810     +5   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          42796      42810    +14   
+ Misses         8009       8000     -9   
  Partials          0          0          

Powered by Codecov. Last updated by 62b4327...9d93fea

if copy or data.dtype != cls._default_dtype:
subarr = np.array(data, dtype=cls._default_dtype, copy=copy)
if not ((subarr == data) | np.isnan(subarr)).all():
raise TypeError('Unsafe NumPy casting, you must '
Copy link
Contributor

Choose a reason for hiding this comment

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

this is extremely expensive to compare things like this,why are you doingit?

@toobaz toobaz force-pushed the numindexname branch 3 times, most recently from 8b6b37a to 62ec329 Compare May 17, 2016 19:29
@toobaz
Copy link
Member Author

toobaz commented May 17, 2016

Removed dtype check and the related tests. Sorry for filling up the Travis queue... three of the tests can be canceled.

@@ -82,8 +84,6 @@ def __new__(cls, levels=None, labels=None, sortorder=None, names=None,
if len(levels) == 1:
if names:
name = names[0]
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you removing this? names/name are equivalent (I think this is taken care above), pls confirm.

@toobaz toobaz force-pushed the numindexname branch 2 times, most recently from 3479f9b to fe55399 Compare May 18, 2016 07:13
@toobaz
Copy link
Member Author

toobaz commented May 18, 2016

(removed code for name handling in MultiIndex, which is now special-cased in the relative test)

@toobaz toobaz force-pushed the numindexname branch 2 times, most recently from 40cd25b to 798b23f Compare May 18, 2016 07:23
def test_ensure_copied_data(self):
# GH12309
for name, index in compat.iteritems(self.indices):
if isinstance(index, (PeriodIndex, RangeIndex, MultiIndex)):
Copy link
Contributor

Choose a reason for hiding this comment

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

so then these need specific tests (name this the same as this one and put in the appropriate place)

----------
orig : ndarray
other ndarray to compare self._data against
copy : boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

make this a default parameter of False.

@toobaz
Copy link
Member Author

toobaz commented Jun 5, 2016

Added the new tests, will have to update a couple of calls when we decide what to do in #13355, but that can be done there, and I wouldn't wait (at least, I personally don't want to spend more time on this PR).

@jreback
Copy link
Contributor

jreback commented Jun 5, 2016

@toobaz no this looks fine. just wanted @sinhrks to have a look.

@jreback
Copy link
Contributor

jreback commented Jun 5, 2016

#13355 can fix it if desired (but to be honest that is lessening the strictness of tests), but can decide there.

with assertRaisesRegexp(AssertionError, expected):
assert_numpy_array_equal(a, b, check_same='same')
expected = 'array\(\[1, 2, 3\]\) is array\(\[1, 2, 3\]\)'
with assertRaisesRegexp(AssertionError, expected):
Copy link
Contributor

Choose a reason for hiding this comment

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

good

@toobaz
Copy link
Member Author

toobaz commented Jun 12, 2016

ping @sinhrks

@@ -343,7 +343,8 @@ Bug Fixes
- Bug in ``.tz_convert`` on a tz-aware ``DateTimeIndex`` that relied on index being sorted for correct results (:issue: `13306`)



- Bug in various index types, which did not propagate the name of passed index (:issue:`12309`)
- Bug in ``DateTimeIndex``, which did not honour the ``copy=True`` (:issue:`13205`)
Copy link
Member

Choose a reason for hiding this comment

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

DatetimeIndex

@sinhrks
Copy link
Member

sinhrks commented Jun 12, 2016

Thx for update. Few minor comments.

@toobaz
Copy link
Member Author

toobaz commented Jun 12, 2016

@sinhrks done, thanks

@toobaz
Copy link
Member Author

toobaz commented Jun 14, 2016

( @jreback : I think we're ready)

@jreback jreback closed this in 07761c5 Jun 14, 2016
@jreback
Copy link
Contributor

jreback commented Jun 14, 2016

thanks @toobaz the internal refactorings can take some time. great for sticking with it!

@toobaz
Copy link
Member Author

toobaz commented Jun 14, 2016

Hope I've learned a bit that will help me need less passages next time ;-)

@toobaz toobaz deleted the numindexname branch July 26, 2016 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Int64Index and Float64Index (and... ?) do not propagate name of passed index
4 participants