Skip to content

Handle FutureWarning from NumPy in Series Construction #22698

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
TomAugspurger opened this issue Sep 13, 2018 · 4 comments · Fixed by #26966
Closed

Handle FutureWarning from NumPy in Series Construction #22698

TomAugspurger opened this issue Sep 13, 2018 · 4 comments · Fixed by #26966
Labels
Blocker Blocking issue or pull request for an upcoming release Compat pandas objects compatability with Numpy or Python functions
Milestone

Comments

@TomAugspurger
Copy link
Contributor

This is with NumPy dev.

In [2]: pd.Series(['0', '1'], dtype=float)
/Users/taugspurger/sandbox/numpy/numpy/core/numeric.py:2468: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  return bool(asarray(a1 == a2).all())
Out[2]:
0    0.0
1    1.0
dtype: float64

https://travis-ci.org/pandas-dev/pandas/jobs/427640030#L5344

this goes from core.series._sanitize_array -> _try_cast -> maybe_cast_to_integer_array.

@TomAugspurger TomAugspurger added Compat pandas objects compatability with Numpy or Python functions Blocker Blocking issue or pull request for an upcoming release Difficulty Intermediate labels Sep 13, 2018
@TomAugspurger TomAugspurger added this to the 0.24.0 milestone Sep 13, 2018
@TomAugspurger
Copy link
Contributor Author

Also want to look at cmp_method in pandas/core/arrays/datetimelike.py

@jorisvandenbossche
Copy link
Member

The occurrences of that last one:

# numpy will show a DeprecationWarning on invalid elementwise
# comparisons, this will raise in the future
with warnings.catch_warnings(record=True):
with np.errstate(all='ignore'):
result = op(self.values, np.asarray(other))

# numpy will show a DeprecationWarning on invalid elementwise
# comparisons, this will raise in the future
with warnings.catch_warnings(record=True):
with np.errstate(all='ignore'):
result = op(self._data, other)

# numpy will show a DeprecationWarning on invalid elementwise
# comparisons, this will raise in the future
with warnings.catch_warnings(record=True):
with np.errstate(all='ignore'):
result = op(self.values, np.asarray(other))

@jreback jreback modified the milestones: 0.24.0, 0.24.1 Dec 9, 2018
@TomAugspurger
Copy link
Contributor Author

Looking through this again, I'm concerned I was overly-zealous in my filtering in #22699. In particular, the cmp_method ones are probably bad. We're silencing the following

In [6]: pd.Index([1, 2]) == 'a'
/Users/taugspurger/sandbox/pandas/pandas/core/indexes/base.py:84: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  result = op(self.values, np.asarray(other))
Out[6]: False

In [7]: pd.Index([1, 2]) == 1
Out[7]: array([ True, False])

In [8]: pd.Index(['a', 'b']) == 'a'
Out[8]: array([ True, False])

In [9]: pd.Index(['a', 'b']) == 1
Out[9]: array([False, False])

Clearly `Out[6] is the odd one out, so we want NumPy's future behavior. I'm worried now that it'll change without warning, since NumPy was issuing the warnings but we caught them.

How should we handle this? Is it as simple as not filtering those warnings?

@TomAugspurger
Copy link
Contributor Author

Though I think we're OK pushing this to 0.24.2 or 0.25, since NumPy just had a release.

@TomAugspurger TomAugspurger modified the milestones: 0.24.1, 0.24.2 Feb 1, 2019
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.24.2, 0.24.3 Mar 11, 2019
@jreback jreback modified the milestones: 0.24.3, Contributions Welcome Apr 20, 2019
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Jun 20, 2019
@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Blocking issue or pull request for an upcoming release Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants