Method: Polars::IO#scan_csv
- Defined in:
- lib/polars/io/csv.rb
#scan_csv(source, has_header: true, separator: ",", comment_prefix: nil, quote_char: '"', skip_rows: 0, skip_lines: 0, schema: nil, schema_overrides: nil, null_values: nil, missing_utf8_is_empty_string: false, ignore_errors: false, cache: true, with_column_names: nil, infer_schema: true, infer_schema_length: N_INFER_DEFAULT, n_rows: nil, encoding: "utf8", low_memory: false, rechunk: false, skip_rows_after_header: 0, row_index_name: nil, row_index_offset: 0, try_parse_dates: false, eol_char: "\n", new_columns: nil, raise_if_empty: true, truncate_ragged_lines: false, decimal_comma: false, glob: true, storage_options: nil, credential_provider: "auto", retries: nil, file_cache_ttl: nil, include_file_paths: nil) ⇒ LazyFrame
Lazily read from a CSV file or multiple files via glob patterns.
This allows the query optimizer to push down predicates and projections to the scan level, thereby potentially reducing memory overhead.
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
# File 'lib/polars/io/csv.rb', line 653 def scan_csv( source, has_header: true, separator: ",", comment_prefix: nil, quote_char: '"', skip_rows: 0, skip_lines: 0, schema: nil, schema_overrides: nil, null_values: nil, missing_utf8_is_empty_string: false, ignore_errors: false, cache: true, with_column_names: nil, infer_schema: true, infer_schema_length: N_INFER_DEFAULT, n_rows: nil, encoding: "utf8", low_memory: false, rechunk: false, skip_rows_after_header: 0, row_index_name: nil, row_index_offset: 0, try_parse_dates: false, eol_char: "\n", new_columns: nil, raise_if_empty: true, truncate_ragged_lines: false, decimal_comma: false, glob: true, storage_options: nil, credential_provider: "auto", retries: nil, file_cache_ttl: nil, include_file_paths: nil ) if new_columns&.any? && schema_overrides.is_a?(::Array) msg = "expected 'schema_overrides' hash, found #{schema_overrides.inspect}" raise TypeError, msg elsif new_columns&.any? if with_column_names msg = "cannot set both `with_column_names` and `new_columns`; mutually exclusive" raise ArgumentError, msg end if schema_overrides && schema_overrides.is_a?(::Array) schema_overrides = new_columns.zip(schema_overrides).to_h end # wrap new column names as a callable with_column_names = lambda do |cols| if cols.length > new_columns.length new_columns + cols[new_columns.length..] else new_columns end end end Utils._check_arg_is_1byte("separator", separator, false) Utils._check_arg_is_1byte("quote_char", quote_char, true) if Utils.pathlike?(source) source = Utils.normalize_filepath(source) end if !infer_schema infer_schema_length = 0 end if !retries.nil? msg = "the `retries` parameter was deprecated in 0.25.0; specify 'max_retries' in `storage_options` instead." Utils.issue_deprecation_warning(msg) = || {} ["max_retries"] = retries end if !file_cache_ttl.nil? msg = "the `file_cache_ttl` parameter was deprecated in 0.25.0; specify 'file_cache_ttl' in `storage_options` instead." Utils.issue_deprecation_warning(msg) = || {} ["file_cache_ttl"] = file_cache_ttl end credential_provider_builder = _init_credential_provider_builder( credential_provider, source, , "scan_csv" ) _scan_csv_impl( source, has_header: has_header, separator: separator, comment_prefix: comment_prefix, quote_char: quote_char, skip_rows: skip_rows, skip_lines: skip_lines, schema_overrides: schema_overrides, schema: schema, null_values: null_values, ignore_errors: ignore_errors, cache: cache, with_column_names: with_column_names, infer_schema_length: infer_schema_length, n_rows: n_rows, low_memory: low_memory, rechunk: rechunk, skip_rows_after_header: skip_rows_after_header, encoding: encoding, row_index_name: row_index_name, row_index_offset: row_index_offset, try_parse_dates: try_parse_dates, eol_char: eol_char, raise_if_empty: raise_if_empty, truncate_ragged_lines: truncate_ragged_lines, decimal_comma: decimal_comma, glob: glob, storage_options: , credential_provider: credential_provider_builder, include_file_paths: include_file_paths ) end |