Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
c7e252cd
Unverified
Commit
c7e252cd
authored
Aug 21, 2023
by
Andrei Ivanov
Committed by
GitHub
Aug 22, 2023
Browse files
Testing a data frame with unnamed columns. (#6186)
parent
9ef80a6e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
6 deletions
+8
-6
docs/source/guide/data-loadcsv.rst
docs/source/guide/data-loadcsv.rst
+1
-1
python/dgl/data/csv_dataset_base.py
python/dgl/data/csv_dataset_base.py
+1
-1
tests/python/common/data/test_data.py
tests/python/common/data/test_data.py
+6
-4
No files found.
docs/source/guide/data-loadcsv.rst
View file @
c7e252cd
...
...
@@ -461,7 +461,7 @@ To parse the string type labels, one can define a ``DataParser`` class as follow
parsed = {}
for header in df:
if 'Unnamed' in header: # Handle Unnamed column
print("Unamed column is found. Ignored...")
print("Un
n
amed column is found. Ignored...")
continue
dt = df[header].to_numpy().squeeze()
if header == 'label':
...
...
python/dgl/data/csv_dataset_base.py
View file @
c7e252cd
...
...
@@ -376,7 +376,7 @@ class DefaultDataParser:
data
=
{}
for
header
in
df
:
if
"Unnamed"
in
header
:
dgl_warning
(
"Unamed column is found. Ignored..."
)
dgl_warning
(
"Un
n
amed column is found. Ignored..."
)
continue
dt
=
df
[
header
].
to_numpy
().
squeeze
()
if
len
(
dt
)
>
0
and
isinstance
(
dt
[
0
],
str
):
...
...
tests/python/common/data/test_data.py
View file @
c7e252cd
...
...
@@ -737,17 +737,19 @@ def _test_construct_graphs_multiple():
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
with
tempfile
.
TemporaryDirectory
()
as
test_dir
:
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
()
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
():
warnings
.
simplefilter
(
"ignore"
,
category
=
UserWarning
)
return
dp
(
df
)
...
...
@@ -785,7 +787,7 @@ def _test_DefaultDataParser():
# csv has index column which is ignored as it's unnamed
df
=
pd
.
DataFrame
({
"label"
:
[
1
,
2
,
3
]})
dt
=
_get_data_table
(
df
)
dt
=
_get_data_table
(
df
,
True
)
assert
len
(
dt
)
==
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment