question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MatplotlibWriter overwrite list of figures does not work.

See original GitHub issue

Description

The latest MatplotlibWriter (which has not been released as stable yet) has an error here: (https://github.com/quantumblacklabs/kedro/blob/b76707669cde0b860389cd24a4397cbce001d13c/kedro/extras/datasets/matplotlib/matplotlib_writer.py#L149)

Where self._filepath is an object of ‘PurePosixPath’ which is not iterable.

Context

I wanted to output a list of matplotlib figures using this dataset and using the new attribute overwrite=True.

Steps to Reproduce

Here is a snippet that reproduces the error:

from kedro.extras.datasets.matplotlib import MatplotlibWriter
import matplotlib.pyplot as plt

# We run save twice so that the figure is overwritten the second time:
for i in range(2):

    dataset = MatplotlibWriter(filepath='test', overwrite=True)
    figs = []
    for i in range(3):
        fig,ax=plt.subplots()
        ax.plot([1,2,3])
        figs.append(fig)
        
    dataset.save(figs)
TypeError: 'PurePosixPath' object is not iterable

Solution suggestion:

Convert the PurePosixPath object to string solves the problem: self._fs.rm(str(self._filepath), recursive=True)

Your Environment

Include as many relevant details about the environment in which you experienced the bug:

  • Kedro (latest) (current stable 0.17.5 does not have overwrite attribute):
  • Python version used 3.7
  • Operating system and version: Win10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
deepyamancommented, Dec 6, 2021

@deepyaman Yeah, I think that sounds correct. If you have both versioning and overwrite on then it should check to see whether the specific timestamped directory you’re trying to save to already exists, and if it does then remove it. As you say, this will only actually delete anything if you’ve manually specified a version timestamp that already exists. It’s quite an edge case but this sounds safest overall rather than deleting the whole directory hierarchy.

https://github.com/quantumblacklabs/kedro/blob/ae80b129cb4f1973a554af964d48d8af0c355bb9/kedro/io/core.py#L582-L586 makes it seem that, by default, you couldn’t write to an already existing directory. In that case, rather than implementing custom logic, should we just raise a warning (something like “overwrite can’t be set when versioning”) and set overwrite to False?

0reactions
AntonyMilneQBcommented, Dec 6, 2021

@deepyaman Yeah, I think that sounds correct. If you have both versioning and overwrite on then it should check to see whether the specific timestamped directory you’re trying to save to already exists, and if it does then remove it. As you say, this will only actually delete anything if you’ve manually specified a version timestamp that already exists. It’s quite an edge case but this sounds safest overall rather than deleting the whole directory hierarchy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MatplotlibWriter overwrite list of figures does not work. · Issue #1085 ...
I wanted to output a list of matplotlib figures using this dataset and using the new attribute overwrite=True. Steps to Reproduce. Here is...
Read more >
kedro.extras.datasets.matplotlib.MatplotlibWriter
Example saving multiple plots in a folder, using a list: import matplotlib.pyplot as plt ... Has no effect on the data set if...
Read more >
Matplotlib figure not working [duplicate] - Stack Overflow
Here, declaring plt.figure(...) in the end means you are creating a whole new plot after you've drawn into the last one. You don't...
Read more >
Tutorial - Bar Chart Race - Dexplo
The data below is an example of properly formatted data. ... A single main function, bar_chart_race , exists to create the animations.
Read more >
kedro Changelog - pyup.io
Setup subscription for auto update of experiment runs list on new Kedro runs. ... Please note that release >=3.8.0 will not work with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found