"tests/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "aa884d43b6c9c4f6f706ca49a0f509552c1915e9"
Unverified Commit c7e252cd authored by Andrei Ivanov's avatar Andrei Ivanov Committed by GitHub
Browse files

Testing a data frame with unnamed columns. (#6186)

parent 9ef80a6e
...@@ -461,7 +461,7 @@ To parse the string type labels, one can define a ``DataParser`` class as follow ...@@ -461,7 +461,7 @@ To parse the string type labels, one can define a ``DataParser`` class as follow
parsed = {} parsed = {}
for header in df: for header in df:
if 'Unnamed' in header: # Handle Unnamed column if 'Unnamed' in header: # Handle Unnamed column
print("Unamed column is found. Ignored...") print("Unnamed column is found. Ignored...")
continue continue
dt = df[header].to_numpy().squeeze() dt = df[header].to_numpy().squeeze()
if header == 'label': if header == 'label':
......
...@@ -376,7 +376,7 @@ class DefaultDataParser: ...@@ -376,7 +376,7 @@ class DefaultDataParser:
data = {} data = {}
for header in df: for header in df:
if "Unnamed" in header: if "Unnamed" in header:
dgl_warning("Unamed column is found. Ignored...") dgl_warning("Unnamed column is found. Ignored...")
continue continue
dt = df[header].to_numpy().squeeze() dt = df[header].to_numpy().squeeze()
if len(dt) > 0 and isinstance(dt[0], str): if len(dt) > 0 and isinstance(dt[0], str):
......
...@@ -737,17 +737,19 @@ def _test_construct_graphs_multiple(): ...@@ -737,17 +737,19 @@ def _test_construct_graphs_multiple():
assert expect_except assert expect_except
def _get_data_table(data_frame): def _get_data_table(data_frame, save_index=False):
from dgl.data.csv_dataset_base import DefaultDataParser from dgl.data.csv_dataset_base import DefaultDataParser
with tempfile.TemporaryDirectory() as test_dir: with tempfile.TemporaryDirectory() as test_dir:
csv_path = os.path.join(test_dir, "nodes.csv") csv_path = os.path.join(test_dir, "nodes.csv")
data_frame.to_csv(csv_path, index=False) data_frame.to_csv(csv_path, index=save_index)
dp = DefaultDataParser() dp = DefaultDataParser()
df = pd.read_csv(csv_path) df = pd.read_csv(csv_path)
# Intercepting the warning: "Unamed column is found. Ignored...". # Warning suppression : "Untitled column found. Ignored...",
# which appears when a CSV file is saved with an index:
# data_frame.to_csv(csv_path, index=True).
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning) warnings.simplefilter("ignore", category=UserWarning)
return dp(df) return dp(df)
...@@ -785,7 +787,7 @@ def _test_DefaultDataParser(): ...@@ -785,7 +787,7 @@ def _test_DefaultDataParser():
# csv has index column which is ignored as it's unnamed # csv has index column which is ignored as it's unnamed
df = pd.DataFrame({"label": [1, 2, 3]}) df = pd.DataFrame({"label": [1, 2, 3]})
dt = _get_data_table(df) dt = _get_data_table(df, True)
assert len(dt) == 1 assert len(dt) == 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment