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

Avoid overwriting a variable with value of different type. #1505

Merged
merged 1 commit into from
Jan 20, 2021

Conversation

obi1kenobi
Copy link
Contributor

Description

Avoids the following mypy error:

arviz/plots/traceplot.py:183: error: "InferenceData" has no attribute "dims"  [attr-defined]

Part of #1496.

The error was happening because the data variable was initially of type InferenceData but was later overwritten with a value of different type on the line:

data = get_coords(convert_to_dataset(data, group="posterior"), coords)

In general, assigning a value of a completely different type to an existing variable will cause both mypy and pylint to complain about the assignment itself. In this case, the get_coords() function itself was not type-hinted, i.e. its return type was considered to be Any. This led mypy to incorrectly deduce that the return type must have preserved the existing type of data, because not doing so would have been an immediate error.

Renaming the assignment on that line to a new variable name avoids the current error as well as the possible future mypy or pylint errors arising when and if get_coords() gets a type hint for its return type.

Checklist

  • Follows official PR format
  • Code style correct (follows pylint and black guidelines)

@codecov
Copy link

codecov bot commented Jan 19, 2021

Codecov Report

Merging #1505 (cc96b1f) into master (14875f5) will not change coverage.
The diff coverage is 80.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1505   +/-   ##
=======================================
  Coverage   91.76%   91.76%           
=======================================
  Files         105      105           
  Lines       11316    11316           
=======================================
  Hits        10384    10384           
  Misses        932      932           
Impacted Files Coverage Δ
arviz/plots/traceplot.py 95.12% <80.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14875f5...cc96b1f. Read the comment docs.

@ColCarroll
Copy link
Member

LGTM -- this is interesting, because InferenceData is not an xarray dataset, but it pretends to be. I guess this is actually a helpful distinction, because data has properties hanging off it, while data.posterior does not.

@ColCarroll ColCarroll merged commit f3b7ee3 into arviz-devs:master Jan 20, 2021
@obi1kenobi obi1kenobi deleted the fix_traceplot branch July 4, 2021 14:27
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.

2 participants