|
13 | 13 | """Placeholder docstring"""
|
14 | 14 | from __future__ import print_function, absolute_import
|
15 | 15 |
|
16 |
| -import csv |
17 |
| -from six import StringIO |
18 |
| -import numpy as np |
19 |
| - |
20 |
| -from sagemaker.content_types import CONTENT_TYPE_CSV |
21 | 16 | from sagemaker.deserializers import BaseDeserializer
|
22 | 17 | from sagemaker.model_monitor import DataCaptureConfig
|
23 | 18 | from sagemaker.serializers import BaseSerializer
|
@@ -490,105 +485,3 @@ def deserialize(self, data, content_type):
|
490 | 485 | def ACCEPT(self):
|
491 | 486 | """The content type that is expected from the inference endpoint."""
|
492 | 487 | return self.accept
|
493 |
| - |
494 |
| - |
495 |
| -class _CsvSerializer(object): |
496 |
| - """Placeholder docstring""" |
497 |
| - |
498 |
| - def __init__(self): |
499 |
| - """Placeholder docstring""" |
500 |
| - self.content_type = CONTENT_TYPE_CSV |
501 |
| - |
502 |
| - def __call__(self, data): |
503 |
| - """Take data of various data formats and serialize them into CSV. |
504 |
| -
|
505 |
| - Args: |
506 |
| - data (object): Data to be serialized. |
507 |
| -
|
508 |
| - Returns: |
509 |
| - object: Sequence of bytes to be used for the request body. |
510 |
| - """ |
511 |
| - # For inputs which represent multiple "rows", the result should be newline-separated CSV |
512 |
| - # rows |
513 |
| - if _is_mutable_sequence_like(data) and len(data) > 0 and _is_sequence_like(data[0]): |
514 |
| - return "\n".join([_CsvSerializer._serialize_row(row) for row in data]) |
515 |
| - return _CsvSerializer._serialize_row(data) |
516 |
| - |
517 |
| - @staticmethod |
518 |
| - def _serialize_row(data): |
519 |
| - # Don't attempt to re-serialize a string |
520 |
| - """ |
521 |
| - Args: |
522 |
| - data: |
523 |
| - """ |
524 |
| - if isinstance(data, str): |
525 |
| - return data |
526 |
| - if isinstance(data, np.ndarray): |
527 |
| - data = np.ndarray.flatten(data) |
528 |
| - if hasattr(data, "__len__"): |
529 |
| - if len(data) == 0: |
530 |
| - raise ValueError("Cannot serialize empty array") |
531 |
| - return _csv_serialize_python_array(data) |
532 |
| - |
533 |
| - # files and buffers |
534 |
| - if hasattr(data, "read"): |
535 |
| - return _csv_serialize_from_buffer(data) |
536 |
| - |
537 |
| - raise ValueError("Unable to handle input format: ", type(data)) |
538 |
| - |
539 |
| - |
540 |
| -def _csv_serialize_python_array(data): |
541 |
| - """ |
542 |
| - Args: |
543 |
| - data: |
544 |
| - """ |
545 |
| - return _csv_serialize_object(data) |
546 |
| - |
547 |
| - |
548 |
| -def _csv_serialize_from_buffer(buff): |
549 |
| - """ |
550 |
| - Args: |
551 |
| - buff: |
552 |
| - """ |
553 |
| - return buff.read() |
554 |
| - |
555 |
| - |
556 |
| -def _csv_serialize_object(data): |
557 |
| - """ |
558 |
| - Args: |
559 |
| - data: |
560 |
| - """ |
561 |
| - csv_buffer = StringIO() |
562 |
| - |
563 |
| - csv_writer = csv.writer(csv_buffer, delimiter=",") |
564 |
| - csv_writer.writerow(data) |
565 |
| - return csv_buffer.getvalue().rstrip("\r\n") |
566 |
| - |
567 |
| - |
568 |
| -csv_serializer = _CsvSerializer() |
569 |
| - |
570 |
| - |
571 |
| -def _is_mutable_sequence_like(obj): |
572 |
| - """ |
573 |
| - Args: |
574 |
| - obj: |
575 |
| - """ |
576 |
| - return _is_sequence_like(obj) and hasattr(obj, "__setitem__") |
577 |
| - |
578 |
| - |
579 |
| -def _is_sequence_like(obj): |
580 |
| - """ |
581 |
| - Args: |
582 |
| - obj: |
583 |
| - """ |
584 |
| - return hasattr(obj, "__iter__") and hasattr(obj, "__getitem__") |
585 |
| - |
586 |
| - |
587 |
| -def _row_to_csv(obj): |
588 |
| - """ |
589 |
| - Args: |
590 |
| - obj: |
591 |
| - """ |
592 |
| - if isinstance(obj, str): |
593 |
| - return obj |
594 |
| - return ",".join(obj) |
0 commit comments