-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Numindexname #13205
Conversation
expected = Index(i.values.astype(dtype)) | ||
tm.assert_index_equal(result, expected) | ||
i = Float64Index([0, 1, 2]) | ||
result = i.astype('int64') |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(right, fixed)
if name is None and hasattr(levels, 'name'): | ||
name = levels.name | ||
if isinstance(levels, MultiIndex): | ||
return levels.copy(name=name, names=names, deep=copy) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is tested here
Current coverage is 84.25%@@ 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
|
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 ' |
There was a problem hiding this comment.
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?
8b6b37a
to
62ec329
Compare
Removed |
@@ -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: |
There was a problem hiding this comment.
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.
3479f9b
to
fe55399
Compare
(removed code for name handling in |
40cd25b
to
798b23f
Compare
def test_ensure_copied_data(self): | ||
# GH12309 | ||
for name, index in compat.iteritems(self.indices): | ||
if isinstance(index, (PeriodIndex, RangeIndex, MultiIndex)): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
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). |
#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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
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`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DatetimeIndex
Thx for update. Few minor comments. |
@sinhrks done, thanks |
( @jreback : I think we're ready) |
thanks @toobaz the internal refactorings can take some time. great for sticking with it! |
Hope I've learned a bit that will help me need less passages next time ;-) |
git diff upstream/master | flake8 --diff
dtype
s,copy=true
forDateTimeIndex
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 ifdtype
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 ifdtype
is not the expected dtype.