Skip to content

Commit

Permalink
Remove unused utils.pd_read, .pd_write
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Mar 23, 2020
1 parent f551acc commit ddfe9e7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
49 changes: 0 additions & 49 deletions ixmp/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,11 @@
"""Tests for ixmp.utils."""
import pandas as pd
from pandas.testing import assert_frame_equal
import pytest
from pytest import mark, param

from ixmp import utils
from ixmp.testing import populate_test_platform


def make_obs(fname, exp, **kwargs):
utils.pd_write(exp, fname, index=False)
obs = utils.pd_read(fname, **kwargs)
return obs


def test_pd_io_csv(tmp_path):

fname = tmp_path / "test.csv"
exp = pd.DataFrame({'a': [0, 1], 'b': [2, 3]})
obs = make_obs(fname, exp)
assert_frame_equal(obs, exp)


def test_pd_io_xlsx(tmp_path):

fname = tmp_path / "test.xlsx"
exp = pd.DataFrame({'a': [0, 1], 'b': [2, 3]})
obs = make_obs(fname, exp)
assert_frame_equal(obs, exp)


def test_pd_io_xlsx_multi(tmp_path):

fname = tmp_path / "test.xlsx"
exp = {
'sheet1': pd.DataFrame({'a': [0, 1], 'b': [2, 3]}),
'sheet2': pd.DataFrame({'c': [4, 5], 'd': [6, 7]}),
}
obs = make_obs(fname, exp, sheet_name=None)
for k, _exp in exp.items():
_obs = obs[k]
assert_frame_equal(_obs, _exp)


def test_pd_write(tmp_path):

fname = 'test.csv'
d = tmp_path / "sub"
d.mkdir()

data_frame = [1, 2, 3, 4]

with pytest.raises(ValueError):
assert utils.pd_write(data_frame, fname)


def test_check_year():

# If y is a string value, raise a Value Error.
Expand Down
28 changes: 0 additions & 28 deletions ixmp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from urllib.parse import urlparse

import pandas as pd
from pathlib import Path


# globally accessible logger
Expand Down Expand Up @@ -119,33 +118,6 @@ def parse_url(url):
return platform_info, scenario_info


def pd_read(f, *args, **kwargs):
"""Try to read a file with pandas, no fancy stuff"""
f = Path(f)
if f.suffix == '.csv':
return pd.read_csv(f, *args, **kwargs)
else:
return pd.read_excel(f, *args, **kwargs)


def pd_write(df, f, *args, **kwargs):
"""Try to write one or more dfs with pandas, no fancy stuff"""
f = Path(f)
is_pd = isinstance(df, (pd.DataFrame, pd.Series))
if f.suffix == '.csv':
if not is_pd:
raise ValueError('Must pass a Dataframe if using csv files')
df.to_csv(f, *args, **kwargs)
else:
writer = pd.ExcelWriter(f, engine='xlsxwriter')
if is_pd:
sheet_name = kwargs.pop('sheet_name', 'Sheet1')
df = {sheet_name: df}
for k, v in df.items():
v.to_excel(writer, sheet_name=k, *args, **kwargs)
writer.save()


def year_list(x):
"""Return the elements of x that can be cast to year (int)."""
lst = []
Expand Down

1 comment on commit ddfe9e7

@Jihoon
Copy link
Contributor

@Jihoon Jihoon commented on ddfe9e7 Mar 31, 2020

Choose a reason for hiding this comment

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

Hi Paul @khaeru, I can see this pd_* are still getting imported in core.py in message_ix. iiasa/message_ix#324

Please sign in to comment.