|
1 | 1 | import contextlib |
2 | 2 | import csv |
3 | 3 | import locale |
| 4 | +import os |
4 | 5 | import pickle |
5 | 6 | import re |
6 | 7 | import subprocess |
@@ -668,6 +669,14 @@ def read(self): |
668 | 669 | try: |
669 | 670 | reader = csv.reader(file, dialect=dialect) |
670 | 671 | data = self.data_table(reader) |
| 672 | + |
| 673 | + # TODO: Name can be set unconditionally when/if |
| 674 | + # self.filename will always be a string with the file name. |
| 675 | + # Currently, some tests pass StringIO instead of |
| 676 | + # the file name to a reader. |
| 677 | + if isinstance(self.filename, str): |
| 678 | + data.name = os.path.splitext( |
| 679 | + os.path.split(self.filename)[-1])[0] |
671 | 680 | if error and isinstance(error, UnicodeDecodeError): |
672 | 681 | pos, endpos = error.args[2], error.args[3] |
673 | 682 | warning = ('Skipped invalid byte(s) in position ' |
@@ -731,8 +740,10 @@ def constr_vars(inds): |
731 | 740 | classes = constr_vars(class_indices) |
732 | 741 | meta_attrs = constr_vars(meta_indices) |
733 | 742 | domain = Domain(attrs, classes, meta_attrs) |
734 | | - return Table.from_numpy( |
| 743 | + table = Table.from_numpy( |
735 | 744 | domain, attrs and X, classes and Y, metas and meta_attrs) |
| 745 | + table.name = os.path.splitext(os.path.split(self.filename)[-1])[0] |
| 746 | + return table |
736 | 747 |
|
737 | 748 |
|
738 | 749 | class ExcelReader(FileFormat): |
@@ -767,6 +778,9 @@ def read(self): |
767 | 778 | for col in range(first_col, row_len)] |
768 | 779 | for row in range(first_row, ss.nrows)]) |
769 | 780 | table = self.data_table(cells) |
| 781 | + table.name = os.path.splitext(os.path.split(self.filename)[-1])[0] |
| 782 | + if self.sheet: |
| 783 | + table.name = '-'.join((table.name, self.sheet)) |
770 | 784 | except Exception: |
771 | 785 | raise IOError("Couldn't load spreadsheet from " + self.filename) |
772 | 786 | return table |
|
0 commit comments