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

Deprecate DataSet.vectors #1461

Merged
merged 9 commits into from
Jun 29, 2021
Merged

Conversation

MatthewFlamm
Copy link
Contributor

@MatthewFlamm MatthewFlamm commented Jun 28, 2021

Overview

As discussed in #1430, this PR deprecates the usage of DataSet.vectors to set and retrieve vector data. Today, pyvista does not explicitly distinguish between vector and scalar data other than DataSet.active_vectors and related methods.

The DataSet.vectors usage is a simple shorthand for

DataSet['_vectors'] = data
DataSet.active_vectors_name = "_vectors"

This however leads to confusion as there is no special method for setting/retrieving scalars, tensors, etc.... (see pyvista/pyvista-support#448). It is also unintuitive to have a key with a leading underscore, which suggest that this shouldn't be used by users.

Details

Related to #1431, but not directly.

Closes #1430.

The warning message looks like:

pyvista/pyvista/core/dataset.py:256: PyvistaDeprecationWarning: Use of `DataSet.vectors` to add vector data is deprecated. Use `DataSet['vector_name'] = data` or `DataSet.point_arrays['vector_name'] = data` or `DataSet.cell_arrays['vector_name'] = data`. Use `DataSet.set_active_vectors('vector_name')` or `DataSet.active_vectors_name = 'vector_name' to make active.

I'm not sure why there is a hanging warnings.warn( at the end. I think I followed the same logic as the other deprecations in the codebase.

@codecov
Copy link

codecov bot commented Jun 28, 2021

Codecov Report

Merging #1461 (eb7216e) into main (8d0fe22) will decrease coverage by 0.06%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##             main    #1461      +/-   ##
==========================================
- Coverage   90.05%   89.98%   -0.07%     
==========================================
  Files          65       65              
  Lines       12437    12460      +23     
==========================================
+ Hits        11200    11212      +12     
- Misses       1237     1248      +11     

Copy link
Member

@tkoyama010 tkoyama010 left a comment

Choose a reason for hiding this comment

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

@MatthewFlamm Thanks for PR. Awesome job! I have 1 comment.

pyvista/examples/examples.py Outdated Show resolved Hide resolved
Co-authored-by: Tetsuo Koyama <[email protected]>
examples/01-filter/glyphs.py Outdated Show resolved Hide resolved
pyvista/core/dataset.py Outdated Show resolved Hide resolved
@adeak
Copy link
Member

adeak commented Jun 28, 2021

I'm not sure why there is a hanging warnings.warn( at the end. I think I followed the same logic as the other deprecations in the codebase.

When you raise a warning or an error the exact line that emits the warning or error is also shown. This is normal. But when there are linebreaks in the line that emits the warning or error, only the first line is printed:

$ cat tmp.py
raise ValueError('potato '
       'potahtoe')

$ python tmp.py 
Traceback (most recent call last):
  File "/home/adeak/tmp.py", line 1, in <module>
    raise ValueError('potato '
ValueError: potato potahtoe

@MatthewFlamm
Copy link
Contributor Author

When you raise a warning or an error the exact line that emits the warning or error is also shown. This is normal. But when there are linebreaks in the line that emits the warning or error, only the first line is printed:

This I learned today. This makes it important to include something on that first line.

@adeak
Copy link
Member

adeak commented Jun 28, 2021

I wouldn't worry about it too much. At worst one could define the long message in a separate variable and then have the warning on a single line.

@tkoyama010 tkoyama010 merged commit f2ff307 into pyvista:main Jun 29, 2021
adeak added a commit to adeak/pyvista that referenced this pull request Jul 10, 2021
* upstream/main: (27 commits)
  Add additional ray trace example (pyvista#1502)
  Add legend face option (pyvista#1496)
  Improve dataset filter examples (pyvista#1482)
  narrow mac version testing (pyvista#1495)
  📸 Add copy method to camera object (pyvista#1328)
  Scalar preferences (pyvista#1454)
  Minor post-PR cleanup (pyvista#1490)
  Fix boolean behavior (pyvista#1485)
  Add evenly spaced streamlines 2D filter (pyvista#1441)
  Do not return cpos by default (pyvista#1478)
  Add and improve examples (pyvista#1479)
  ignore debugleaks 'warning' (pyvista#1477)
  Revert "by default do not return the camera position"
  by default do not return the camera position
  Add pyvista plot directive (pyvista#1457)
  Update show_bounds kwargs, remove needless example import (pyvista#1466)
  Deprecate `DataSet.vectors` (pyvista#1461)
  add installation notes (pyvista#1462)
  📝 Fix typo in rotate_y docs (pyvista#1458)
  only allow dataset types to be active (pyvista#1451)
  ...
@akaszynski akaszynski mentioned this pull request Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataSet.vectors does not work with cell data
3 participants