Skip to content

Commit 666896c

Browse files
committed
rewinded changes in core/session.py --> to_csv, to_excel and to_pickle will be updated in separate PRs
1 parent 8ff70ce commit 666896c

File tree

2 files changed

+23
-68
lines changed

2 files changed

+23
-68
lines changed

doc/source/changes/version_0_29.rst.inc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ Miscellaneous improvements
4343
>>> s2
4444
Session(arr1, arr2, a, b, a01)
4545

46-
Note: all axes (groups) of a session are stored in the same CSV file/Excel sheet/HDF group
47-
named __axes__ (__groups__).
48-
4946

5047
Fixes
5148
-----

larray/core/session.py

Lines changed: 23 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,6 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False,
280280
display : bool, optional
281281
Whether or not to display which file is being worked on. Defaults to False.
282282
283-
Notes
284-
-----
285-
When session's objects are saved in CSV files:
286-
287-
- each array is saved in a separate file
288-
- all Axis objects are saved together in the same CSV file named __axes__.csv
289-
- all Group objects are saved together in the same CSV file named __groups__.csv
290-
291-
When saving session's objects to an Excel file:
292-
293-
- each array is saved in a separate sheet
294-
- all Axis objects are saved together in the same sheet named __axes__
295-
- all Group objects are saved together in the same sheet named __groups__
296-
297283
Examples
298284
--------
299285
>>> # axes
@@ -325,7 +311,10 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False,
325311
engine = ext_default_engine[ext]
326312
handler_cls = handler_classes[engine]
327313
handler = handler_cls(fname, overwrite)
328-
items = self.items()
314+
if engine != 'pandas_hdf':
315+
items = self.filter(kind=LArray).items()
316+
else:
317+
items = self.items()
329318
if names is not None:
330319
names_set = set(names)
331320
items = [(k, v) for k, v in items if k in names_set]
@@ -398,18 +387,17 @@ def to_globals(self, names=None, depth=0, warn=True, inplace=False):
398387

399388
def to_pickle(self, fname, names=None, overwrite=True, display=False, **kwargs):
400389
"""
401-
Dumps LArray, Axis and Group objects from the current session to a file using pickle.
390+
Dumps all array objects from the current session to a file using pickle.
402391
403392
WARNING: never load a pickle file (.pkl or .pickle) from an untrusted source, as it can lead to arbitrary code
404393
execution.
405394
406395
Parameters
407396
----------
408397
fname : str
409-
Path of the file for the dump.
398+
Path for the dump.
410399
names : list of str or None, optional
411-
Names of LArray/Axis/Group objects to dump.
412-
Defaults to all objects present in the Session.
400+
List of names of objects to dump. Defaults to all objects present in the Session.
413401
overwrite: bool, optional
414402
Whether or not to overwrite an existing file, if any.
415403
If False, file is updated. Defaults to True.
@@ -418,22 +406,16 @@ def to_pickle(self, fname, names=None, overwrite=True, display=False, **kwargs):
418406
419407
Examples
420408
--------
421-
>>> # axes
422-
>>> a, b = Axis("a=a0..a2"), Axis("b=b0..b2") # doctest: +SKIP
423-
>>> # groups
424-
>>> a01 = a['a0,a1'] >> 'a01' # doctest: +SKIP
425-
>>> # arrays
426-
>>> arr1, arr2 = ndtest((a, b)), ndtest(a) # doctest: +SKIP
427-
>>> s = Session([('a', a), ('b', b), ('a01', a01), ('arr1', arr1), ('arr2', arr2)]) # doctest: +SKIP
428-
409+
>>> arr1, arr2, arr3 = ndtest((2, 2)), ndtest(4), ndtest((3, 2)) # doctest: +SKIP
410+
>>> s = Session([('arr1', arr1), ('arr2', arr2), ('arr3', arr3)]) # doctest: +SKIP
429411
430412
Save all arrays
431413
432414
>>> s.to_pickle('output.pkl') # doctest: +SKIP
433415
434-
Save only some objects
416+
Save only some arrays
435417
436-
>>> s.to_pickle('output.pkl', ['a', 'b', 'arr1']) # doctest: +SKIP
418+
>>> s.to_pickle('output.pkl', ['arr1', 'arr3']) # doctest: +SKIP
437419
"""
438420
self.save(fname, names, ext_default_engine['pkl'], overwrite, display, **kwargs)
439421

@@ -480,85 +462,61 @@ def to_hdf(self, fname, names=None, overwrite=True, display=False, **kwargs):
480462

481463
def to_excel(self, fname, names=None, overwrite=True, display=False, **kwargs):
482464
"""
483-
Dumps LArray, Axis and Group objects from the current session to an Excel file.
465+
Dumps all array objects from the current session to an Excel file.
484466
485467
Parameters
486468
----------
487469
fname : str
488-
Path of the file for the dump.
470+
Path for the dump.
489471
names : list of str or None, optional
490-
Names of LArray/Axis/Group objects to dump.
491-
Defaults to all objects present in the Session.
472+
List of names of objects to dump. Defaults to all objects present in the Session.
492473
overwrite: bool, optional
493474
Whether or not to overwrite an existing file, if any. If False, file is updated. Defaults to True.
494475
display : bool, optional
495476
Whether or not to display which file is being worked on. Defaults to False.
496477
497-
Notes
498-
-----
499-
- each array is saved in a separate sheet
500-
- all Axis objects are saved together in the same sheet named __axes__
501-
- all Group objects are saved together in the same sheet named __groups__
502-
503478
Examples
504479
--------
505-
>>> # axes
506-
>>> a, b = Axis("a=a0..a2"), Axis("b=b0..b2") # doctest: +SKIP
507-
>>> # groups
508-
>>> a01 = a['a0,a1'] >> 'a01' # doctest: +SKIP
509-
>>> # arrays
510-
>>> arr1, arr2 = ndtest((a, b)), ndtest(a) # doctest: +SKIP
511-
>>> s = Session([('a', a), ('b', b), ('a01', a01), ('arr1', arr1), ('arr2', arr2)]) # doctest: +SKIP
480+
>>> arr1, arr2, arr3 = ndtest((2, 2)), ndtest(4), ndtest((3, 2)) # doctest: +SKIP
481+
>>> s = Session([('arr1', arr1), ('arr2', arr2), ('arr3', arr3)]) # doctest: +SKIP
512482
513483
Save all arrays
514484
515485
>>> s.to_excel('output.xlsx') # doctest: +SKIP
516486
517-
Save only some objects
487+
Save only some arrays
518488
519-
>>> s.to_excel('output.xlsx', ['a', 'b', 'arr1']) # doctest: +SKIP
489+
>>> s.to_excel('output.xlsx', ['arr1', 'arr3']) # doctest: +SKIP
520490
"""
521491
self.save(fname, names, ext_default_engine['xlsx'], overwrite, display, **kwargs)
522492

523493
dump_excel = renamed_to(to_excel, 'dump_excel')
524494

525495
def to_csv(self, fname, names=None, display=False, **kwargs):
526496
"""
527-
Dumps LArray, Axis and Group objects from the current session to CSV files.
497+
Dumps all array objects from the current session to CSV files.
528498
529499
Parameters
530500
----------
531501
fname : str
532502
Path for the directory that will contain CSV files.
533503
names : list of str or None, optional
534-
Names of LArray/Axis/Group objects to dump.
535-
Defaults to all objects present in the Session.
504+
List of names of objects to dump. Defaults to all objects present in the Session.
536505
display : bool, optional
537506
Whether or not to display which file is being worked on. Defaults to False.
538507
539-
Notes
540-
-----
541-
- each array is saved in a separate file
542-
- all Axis objects are saved together in the same CSV file named __axes__.csv
543-
- all Group objects are saved together in the same CSV file named __groups__.csv
544-
545508
Examples
546509
--------
547-
>>> # axes
548-
>>> a, b = Axis("a=a0..a2"), Axis("b=b0..b2") # doctest: +SKIP
549-
>>> # groups
550-
>>> a01 = a['a0,a1'] >> 'a01' # doctest: +SKIP
551-
>>> # arrays
552-
>>> arr1, arr2 = ndtest((a, b)), ndtest(a) # doctest: +SKIP
553-
>>> s = Session([('a', a), ('b', b), ('a01', a01), ('arr1', arr1), ('arr2', arr2)]) # doctest: +SKIP
510+
>>> arr1, arr2, arr3 = ndtest((2, 2)), ndtest(4), ndtest((3, 2)) # doctest: +SKIP
511+
>>> s = Session([('arr1', arr1), ('arr2', arr2), ('arr3', arr3)]) # doctest: +SKIP
554512
555513
Save all arrays
556514
557515
>>> s.to_csv('./Output') # doctest: +SKIP
558516
559517
Save only some arrays
560518
561-
>>> s.to_csv('./Output', ['a', 'b', 'arr1']) # doctest: +SKIP
519+
>>> s.to_csv('./Output', ['arr1', 'arr3']) # doctest: +SKIP
562520
"""
563521
self.save(fname, names, ext_default_engine['csv'], display=display, **kwargs)
564522

0 commit comments

Comments
 (0)