Skip to content

Commit 724bca1

Browse files
committed
Import deprecated from typing_extensions
1 parent d063806 commit 724bca1

File tree

1 file changed

+1
-234
lines changed

1 file changed

+1
-234
lines changed

harp/reader.py

Lines changed: 1 addition & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from numpy import dtype
1313
from pandas import DataFrame, Series
1414
from pandas._typing import Axes # pyright: ignore[reportPrivateImportUsage]
15+
from typing_extensions import deprecated
1516

1617
from harp.io import MessageType, read
1718
from harp.model import BitMask, GroupMask, Model, PayloadMember, Register
@@ -310,240 +311,6 @@ def from_dataset(
310311
else:
311312
raise ValueError("The dataset must be a directory containing a device.yml file.")
312313

313-
@classmethod
314-
def from_file(
315-
cls,
316-
filepath: PathLike,
317-
base_path: Optional[PathLike] = None,
318-
include_common_registers: bool = True,
319-
epoch: Optional[datetime] = None,
320-
keep_type: bool = False,
321-
) -> "DeviceReader":
322-
"""Creates a device reader object from the specified schema yml file.
323-
324-
Parameters
325-
----------
326-
filepath
327-
A path to the device yml schema describing the device.
328-
base_path
329-
The path to attempt to resolve the location of data files.
330-
include_common_registers
331-
Specifies whether to include the set of Harp common registers in the
332-
parsed device schema object. If a parsed device schema object is provided,
333-
this parameter is ignored.
334-
epoch
335-
The default reference datetime at which time zero begins. If specified,
336-
the data frames returned by each register reader will have a datetime index.
337-
keep_type
338-
Specifies whether to include a column with the message type by default.
339-
340-
Returns
341-
-------
342-
A device reader object which can be used to read binary data for each
343-
register or to access metadata about each register. Individual registers
344-
can be accessed using dot notation using the name of the register as the
345-
key.
346-
"""
347-
348-
device = read_schema(filepath, include_common_registers)
349-
if base_path is None:
350-
path = Path(filepath).absolute().resolve()
351-
base_path = path.parent / device.device
352-
else:
353-
base_path = Path(base_path).absolute().resolve() / device.device
354-
355-
reg_readers = {
356-
name: _create_register_handler(device, name, _ReaderParams(base_path, epoch, keep_type))
357-
for name in device.registers.keys()
358-
}
359-
return cls(device, reg_readers)
360-
361-
@classmethod
362-
def from_url(
363-
cls,
364-
url: str,
365-
base_path: Optional[PathLike] = None,
366-
include_common_registers: bool = True,
367-
epoch: Optional[datetime] = None,
368-
keep_type: bool = False,
369-
timeout: int = 5,
370-
) -> "DeviceReader":
371-
"""Creates a device reader object from a url pointing to a device.yml file.
372-
373-
Parameters
374-
----------
375-
url
376-
The url pointing to the device.yml schema describing the device.
377-
base_path
378-
The path to attempt to resolve the location of data files.
379-
include_common_registers
380-
Specifies whether to include the set of Harp common registers in the
381-
parsed device schema object. If a parsed device schema object is provided,
382-
this parameter is ignored.
383-
epoch
384-
The default reference datetime at which time zero begins. If specified,
385-
the data frames returned by each register reader will have a datetime index.
386-
keep_type
387-
Specifies whether to include a column with the message type by default.
388-
timeout
389-
The number of seconds to wait for the server to send data before giving up.
390-
Returns
391-
-------
392-
A device reader object which can be used to read binary data for each
393-
register or to access metadata about each register. Individual registers
394-
can be accessed using dot notation using the name of the register as the
395-
key.
396-
"""
397-
398-
response = requests.get(url, timeout=timeout)
399-
text = response.text
400-
401-
device = read_schema(text, include_common_registers)
402-
if base_path is None:
403-
base_path = Path(device.device).absolute().resolve()
404-
else:
405-
base_path = Path(base_path).absolute().resolve()
406-
407-
reg_readers = {
408-
name: _create_register_handler(device, name, _ReaderParams(base_path, epoch, keep_type))
409-
for name in device.registers.keys()
410-
}
411-
return cls(device, reg_readers)
412-
413-
@classmethod
414-
def from_str(
415-
cls,
416-
schema: str,
417-
base_path: Optional[PathLike] = None,
418-
include_common_registers: bool = True,
419-
epoch: Optional[datetime] = None,
420-
keep_type: bool = False,
421-
) -> "DeviceReader":
422-
"""Creates a device reader object from a string containing a device.yml schema.
423-
424-
Parameters
425-
----------
426-
schema
427-
The string containing the device.yml schema describing the device.
428-
base_path
429-
The path to attempt to resolve the location of data files.
430-
include_common_registers
431-
Specifies whether to include the set of Harp common registers in the
432-
parsed device schema object. If a parsed device schema object is provided,
433-
this parameter is ignored.
434-
epoch
435-
The default reference datetime at which time zero begins. If specified,
436-
the data frames returned by each register reader will have a datetime index.
437-
keep_type
438-
Specifies whether to include a column with the message type by default.
439-
440-
Returns
441-
-------
442-
A device reader object which can be used to read binary data for each
443-
register or to access metadata about each register. Individual registers
444-
can be accessed using dot notation using the name of the register as the
445-
key.
446-
"""
447-
448-
device = read_schema(schema, include_common_registers)
449-
if base_path is None:
450-
base_path = Path(device.device).absolute().resolve()
451-
else:
452-
base_path = Path(base_path).absolute().resolve()
453-
454-
reg_readers = {
455-
name: _create_register_handler(device, name, _ReaderParams(base_path, epoch, keep_type))
456-
for name in device.registers.keys()
457-
}
458-
return cls(device, reg_readers)
459-
460-
@classmethod
461-
def from_model(
462-
cls,
463-
model: Model,
464-
base_path: Optional[PathLike] = None,
465-
epoch: Optional[datetime] = None,
466-
keep_type: bool = False,
467-
) -> "DeviceReader":
468-
"""Creates a device reader object from a parsed device schema object.
469-
470-
Parameters
471-
----------
472-
model
473-
The parsed device schema object describing the device.
474-
base_path
475-
The path to attempt to resolve the location of data files.
476-
epoch
477-
The default reference datetime at which time zero begins. If specified,
478-
the data frames returned by each register reader will have a datetime index.
479-
keep_type
480-
Specifies whether to include a column with the message type by default.
481-
482-
Returns
483-
-------
484-
A device reader object which can be used to read binary data for each
485-
register or to access metadata about each register. Individual registers
486-
can be accessed using dot notation using the name of the register as the
487-
key.
488-
"""
489-
490-
if base_path is None:
491-
base_path = Path(model.device).absolute().resolve()
492-
else:
493-
base_path = Path(base_path).absolute().resolve()
494-
495-
reg_readers = {
496-
name: _create_register_handler(model, name, _ReaderParams(base_path, epoch, keep_type))
497-
for name in model.registers.keys()
498-
}
499-
return cls(model, reg_readers)
500-
501-
@classmethod
502-
def from_dataset(
503-
cls,
504-
dataset: PathLike,
505-
include_common_registers: bool = True,
506-
epoch: Optional[datetime] = None,
507-
keep_type: bool = False,
508-
) -> "DeviceReader":
509-
"""Creates a device reader object from the specified dataset folder.
510-
511-
Parameters
512-
----------
513-
dataset
514-
A path to the dataset folder containing a device.yml schema describing the device.
515-
include_common_registers
516-
Specifies whether to include the set of Harp common registers in the
517-
parsed device schema object. If a parsed device schema object is provided,
518-
this parameter is ignored.
519-
epoch
520-
The default reference datetime at which time zero begins. If specified,
521-
the data frames returned by each register reader will have a datetime index.
522-
keep_type
523-
Specifies whether to include a column with the message type by default.
524-
525-
Returns
526-
-------
527-
A device reader object which can be used to read binary data for each
528-
register or to access metadata about each register. Individual registers
529-
can be accessed using dot notation using the name of the register as the
530-
key.
531-
"""
532-
533-
path = Path(dataset).absolute().resolve()
534-
is_dir = os.path.isdir(path)
535-
if is_dir:
536-
filepath = path / "device.yml"
537-
return cls.from_file(
538-
filepath=filepath,
539-
base_path=path,
540-
include_common_registers=include_common_registers,
541-
epoch=epoch,
542-
keep_type=keep_type,
543-
)
544-
else:
545-
raise ValueError("The dataset must be a directory containing a device.yml file.")
546-
547314

548315
def _compose_parser(
549316
f: Callable[[DataFrame], DataFrame],

0 commit comments

Comments
 (0)