MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / load_frames

Function load_frames

alphapy/frame.py:219–275  ·  view source on GitHub ↗

r"""Read a group of dataframes into memory. Parameters ---------- group : alphapy.Group The collection of frames to be read into memory. directory : str Full directory specification. extension : str File name extension, e.g., ``csv``. separator : str

(group, directory, extension, separator, splits=False)

Source from the content-addressed store, hash-verified

217#
218
219def load_frames(group, directory, extension, separator, splits=False):
220 r"""Read a group of dataframes into memory.
221
222 Parameters
223 ----------
224 group : alphapy.Group
225 The collection of frames to be read into memory.
226 directory : str
227 Full directory specification.
228 extension : str
229 File name extension, e.g., ``csv``.
230 separator : str
231 The delimiter between fields in the file.
232 splits : bool, optional
233 If ``True``, then all the members of the group are stored in
234 separate files corresponding with each member. If ``False``,
235 then the data are stored in a single file.
236
237 Returns
238 -------
239 all_frames : list
240 The list of pandas dataframes loaded from the file location. If
241 the files cannot be located, then ``None`` is returned.
242
243 """
244 logger.info("Loading frames from %s", directory)
245 gname = group.name
246 gspace = group.space
247 # If this is a group analysis, then consolidate the frames.
248 # Otherwise, the frames are already aggregated.
249 all_frames = []
250 if splits:
251 gnames = [item.lower() for item in group.members]
252 for gn in gnames:
253 fname = frame_name(gn, gspace)
254 if fname in Frame.frames:
255 logger.info("Joining Frame %s", fname)
256 df = Frame.frames[fname].df
257 else:
258 logger.info("Data Frame for %s not found", fname)
259 # read file for corresponding frame
260 logger.info("Load Data Frame %s from file", fname)
261 df = read_frame(directory, fname, extension, separator)
262 # add this frame to the consolidated frame list
263 if not df.empty:
264 # set the name
265 df.insert(0, TAG_ID, gn)
266 all_frames.append(df)
267 else:
268 logger.debug("Empty Data Frame for: %s", gn)
269 else:
270 # no splits, so use data from consolidated files
271 fname = frame_name(gname, gspace)
272 df = read_frame(directory, fname, extension, separator)
273 if not df.empty:
274 all_frames.append(df)
275 return all_frames
276

Callers 1

run_analysisFunction · 0.90

Calls 2

frame_nameFunction · 0.85
read_frameFunction · 0.85

Tested by

no test coverage detected