Skip to content

Commit

Permalink
ToCSV uses duplicate_last_bin option for to_csv method when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynikitenko committed May 2, 2020
1 parent 0aa82d6 commit 668914e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 12 additions & 2 deletions lena/output/to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,18 @@ def is_writable_hist(val):
continue

if hasattr(data, "to_csv") and callable(data.to_csv):
text = data.to_csv(separator=self._separator,
header=self._header)
try:
# some classes (like Graph) can have to_csv
# without duplicate_last_bin keyword.
# If it is present, use it.
text = data.to_csv(
separator=self._separator, header=self._header,
duplicate_last_bin=self._duplicate_last_bin
)
except TypeError:
text = data.to_csv(
separator=self._separator, header=self._header
)
## *data.to_csv* may produce context,
## which in this case updates the current context.
# no need to allow this. All necessary context
Expand Down
7 changes: 3 additions & 4 deletions lena/output/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,19 @@ def _make_filename(self, outputc):
filepath = filename + "." + fileext
else:
filepath = filename
def normalize_path(pathname, path):
def normalize_path(path_name, path):
if os.path.isabs(path):
warnings.warn(
"{} must not be absolute path, {} given"
.format(pathname, path),
.format(path_name, path),
RuntimeWarning
)
if path.startswith(os.sep):
# there can be also os.altsep for some fancy systems
path= path[len(os.sep):]
path = path[len(os.sep):]
assert not os.path.isabs(path)
return path
dirname = normalize_path("dirname", dirname)
# filepath is an internal variable created from filename
filepath = normalize_path("filename", filepath)
filepath = os.path.join(self.output_directory, dirname, filepath)

Expand Down

0 comments on commit 668914e

Please sign in to comment.