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

API/DEPR: Remove +/- as setops for Index (GH8227) #14127

Merged

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Aug 31, 2016

xref #13777, deprecations put in place in #8227

  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry

return Index(other + np.array(self))

__iadd__ = __add__

def __sub__(self, other):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not defined in super? so this should raise NotImplementedError I think?

Copy link
Member Author

@jorisvandenbossche jorisvandenbossche Aug 31, 2016

Choose a reason for hiding this comment

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

yep, this is something that I still have to handle.

The problem is that sub/add are added for subclasses in either _add_numericlike_set_methods_disabled or _add_numeric_methods or both ovenwritten (always handled both), but in the base class we only want __add__ and not __sub__

If I leave it in here, I think it should rather raise a TypeError? (for usage of base Index class)

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah TypeError is prob ok too

the only reason to raise NotImplemmeted is that then subclasses could override - but we don't want that

@codecov-io
Copy link

codecov-io commented Aug 31, 2016

Current coverage is 85.25% (diff: 100%)

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

@@             master     #14127   diff @@
==========================================
  Files           139        139          
  Lines         50501      50495     -6   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          43058      43051     -7   
- Misses         7443       7444     +1   
  Partials          0          0          

Powered by Codecov. Last update 4488f18...dbcc655

@jreback
Copy link
Contributor

jreback commented Aug 31, 2016

@jorisvandenbossche we should do this for the RC as well.

@jorisvandenbossche
Copy link
Member Author

@jreback yep, as it is quite a substantial change (for people that ignored the warnings)

Is there a reason that we do not allow numeric ops for the base Index class? (eg pd.Index(['a', 'b'] could have a clear meaning, just letting the objects determine whether an operation can be handled)

Because eg the __add__ in the Index class could benefit from the machinery in _add_numeric_methods_binary (eg to ensure attributes like name are passed correctly. Something that is also not correct on current master)

@jreback
Copy link
Contributor

jreback commented Aug 31, 2016

I think we don't allow numeric operations on Index as only possible one is add for string concat
nothing else makes sense

in general these r not well defined so no reason to allow

@shoyer
Copy link
Member

shoyer commented Aug 31, 2016

I think we should let the objects in the Index decide whether the numeric operation is valid or not. This is the approach NumPy uses for object dtype. For example, one might put decimal objects in a pandas.Index.

@jreback
Copy link
Contributor

jreback commented Aug 31, 2016

the numpy approach leads to lots of bugs and edge cases - constraining things somewhat to not allowing everything on everything is much more user friendly

decimal objects in an Index are a disaster - should not be encouraged

Addition and subtraction of certain Index types performed set operations
(set union and difference). This behaviour was already deprecated since 0.15.0,
and is now disabled and, when possible, ``+``
and ``-`` are used for numeric operations (:issue:`8227`, :issue:`14127`).
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be more specific that 'when possible' (maybe say for numeric & datetimelike)

Copy link
Member Author

Choose a reason for hiding this comment

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

datetimelike not yet (DatetimeIndex - DatetimeIndex does still set op, but this one is a bit more work to remove).

And + also works for strings, so not only numeric. Further, for numeric indices, + and - did already do numeric ops and not setops .. (to make it a bit more complex :-))

So I did not directly come up with a more accurate but simple wording, but if you have a suggestion all ears!

@jorisvandenbossche jorisvandenbossche changed the title [WIP] API/DEPR: Remove +/- as setops for Index (GH8227) API/DEPR: Remove +/- as setops for Index (GH8227) Sep 1, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.19.0, 0.19.0rc Sep 1, 2016
@jorisvandenbossche jorisvandenbossche mentioned this pull request Sep 1, 2016
In [1]: pd.Index(['a', 'b']) + pd.Index(['a', 'c'])
FutureWarning: using '+' to provide set union with Indexes is deprecated, use '|' or .union()
Out[1]: Index(['a', 'b', 'c'], dtype='object')

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 clear that this ONLY applies to Index itself and not-subclasses (maybe show that numeric/datetimelike ops are unchanged)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, will try to clarify

@jreback
Copy link
Contributor

jreback commented Sep 3, 2016

@jorisvandenbossche some small comments, but otherwise lgtm. merge when ready.

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.19.0, 0.19.0rc Sep 7, 2016
trbs added a commit to trbs/pandas that referenced this pull request Sep 12, 2016
…eter

* github.com:pydata/pandas: (554 commits)
  BUG: compat with Stata ver 111
  Fix: F999 dictionary key '2000q4' repeated with different values (pandas-dev#14198)
  BLD: Test for Python 3.5 with C locale
  BUG: DatetimeTZBlock can't assign values near dst boundary
  BUG: union_categorical with Series and cat idx
  BUG: fix str.contains for series containing only nan values
  BUG: Categorical constructor not idempotent with ext dtype
  TST: Make encoded sep check more locale sensitive (pandas-dev#14161)
  DOC: minor typo in 0.19.0 whatsnew file (pandas-dev#14185)
  BUG: fix tz-aware datetime convert to DatetimeIndex (GH 14088)
  BUG : bug in setting a slice of a Series with a np.timedelta64
  RLS: v0.19.0rc1
  DOC: clean-up 0.19.0 whatsnew file (pandas-dev#14176)
  DOC: cleanup build warnings (pandas-dev#14172)
  Add steps to run gbq integration testing to the contributing docs (pandas-dev#14144)
  ENH: concat and append now can handle unordered categories (pandas-dev#13767)
  DEPR: Deprecate pandas.core.datetools (pandas-dev#14105)
  API/DEPR: Remove +/- as setops for DatetimeIndex/PeriodIndex (GH9630) (pandas-dev#14164)
  Fix trivial typo in comment (pandas-dev#14174)
  API/DEPR: Remove +/- as setops for Index (GH8227) (pandas-dev#14127)
  ...
trbs added a commit to trbs/pandas that referenced this pull request Sep 12, 2016
* github.com:pydata/pandas: (554 commits)
  BUG: compat with Stata ver 111
  Fix: F999 dictionary key '2000q4' repeated with different values (pandas-dev#14198)
  BLD: Test for Python 3.5 with C locale
  BUG: DatetimeTZBlock can't assign values near dst boundary
  BUG: union_categorical with Series and cat idx
  BUG: fix str.contains for series containing only nan values
  BUG: Categorical constructor not idempotent with ext dtype
  TST: Make encoded sep check more locale sensitive (pandas-dev#14161)
  DOC: minor typo in 0.19.0 whatsnew file (pandas-dev#14185)
  BUG: fix tz-aware datetime convert to DatetimeIndex (GH 14088)
  BUG : bug in setting a slice of a Series with a np.timedelta64
  RLS: v0.19.0rc1
  DOC: clean-up 0.19.0 whatsnew file (pandas-dev#14176)
  DOC: cleanup build warnings (pandas-dev#14172)
  Add steps to run gbq integration testing to the contributing docs (pandas-dev#14144)
  ENH: concat and append now can handle unordered categories (pandas-dev#13767)
  DEPR: Deprecate pandas.core.datetools (pandas-dev#14105)
  API/DEPR: Remove +/- as setops for DatetimeIndex/PeriodIndex (GH9630) (pandas-dev#14164)
  Fix trivial typo in comment (pandas-dev#14174)
  API/DEPR: Remove +/- as setops for Index (GH8227) (pandas-dev#14127)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants