Skip to content

Commit f87b418

Browse files
authored
Merge pull request #137 from openscm/save-read
Fix write read circularity
2 parents fbde2a0 + e2c6843 commit f87b418

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changelog
44
master
55
------
66

7+
- (`#137 <https://github.com/openscm/scmdata/pull/137>`_) Fix :meth:`scmdata.ScmRun.to_csv` so that writing and reading is circular (i.e. you end up where you started if you write a file and then read it straight back into a new :obj:`scmdata.ScmRun` instance)
8+
79
v0.7.6
810
------
911

src/scmdata/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ def to_csv(self, fname: str, **kwargs: Any) -> None:
18501850
fname
18511851
Path to write the file into
18521852
"""
1853-
self.timeseries().reset_index().to_csv(fname, **kwargs)
1853+
self.timeseries().reset_index().to_csv(fname, **kwargs, index=False)
18541854

18551855
def reduce(self, func, dim=None, axis=None, **kwargs):
18561856
"""

tests/integration/test_io.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os.path
2+
3+
import scmdata
4+
import scmdata.testing
5+
6+
7+
def test_read_write_circularity(test_scm_df_monthly, tmpdir):
8+
tempfile = os.path.join(tmpdir, "test.csv")
9+
10+
test_scm_df_monthly.to_csv(tempfile)
11+
12+
read = scmdata.ScmRun(tempfile)
13+
14+
scmdata.testing.assert_scmdf_almost_equal(read, test_scm_df_monthly)

0 commit comments

Comments
 (0)