Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InexactError for floating-point date/time values #40

Closed
jkrumbiegel opened this issue Apr 2, 2024 · 2 comments
Closed

InexactError for floating-point date/time values #40

jkrumbiegel opened this issue Apr 2, 2024 · 2 comments

Comments

@jkrumbiegel
Copy link
Contributor

jkrumbiegel commented Apr 2, 2024

It seems that millisecond precision throws an error at writing out this data as xpt, as an Int representation is assumed with a Second interval. Is this necessary? If so, probably a more informative error would be better

julia> using DataFrames, ReadStatTables

julia> data = DataFrame(; x = rand(10), y = now() .+ Second.(rand(1:1000, 10)))
10×2 DataFrame
 Row │ x           y
     │ Float64     DateTime
─────┼─────────────────────────────────────
   10.712665    2024-04-02T14:05:52.184
   20.424785    2024-04-02T14:09:53.184
   30.883054    2024-04-02T14:13:02.184
   40.00153941  2024-04-02T14:21:05.184
   50.461878    2024-04-02T14:09:35.184
   60.0248336   2024-04-02T14:12:34.184
   70.520406    2024-04-02T14:10:15.184
   80.939239    2024-04-02T14:22:11.184
   90.867324    2024-04-02T14:22:01.184
  100.795371    2024-04-02T14:17:21.184

julia> ReadStatTables.writestat("test.xpt", data)
10×2 ReadStatTable:
Error showing value of type ReadStatTable{ReadStatColumns}:
ERROR: InexactError: Int64(2.027685952184e9)
Stacktrace:
  [1] Int64
    @ ./float.jl:981 [inlined]
  [2] convert
    @ ./number.jl:7 [inlined]
  [3] Second
    @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/Dates/src/types.jl:61 [inlined]
  [4] *
    @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/Dates/src/periods.jl:90 [inlined]
  [5] *
    @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/Dates/src/periods.jl:91 [inlined]
  [6] Num2DateTime
    @ ~/.julia/packages/ReadStatTables/exgPH/src/datetime.jl:120 [inlined]
  [7] getindex
    @ ~/.julia/packages/MappedArrays/jTqdY/src/MappedArrays.jl:166 [inlined]
  [8] isassigned(A::MappedArrays.MappedArray{…}, i::Int64)
    @ Base ./multidimensional.jl:1603
  [9] isassigned(::PrettyTables.ColumnTable, ::Int64, ::Int64)
    @ PrettyTables ~/.julia/packages/PrettyTables/E8rPJ/src/tables.jl:51
 [10] _get_element(ptable::PrettyTables.ProcessedTable, i::Int64, j::Int64)
    @ PrettyTables ~/.julia/packages/PrettyTables/E8rPJ/src/processed_table/get.jl:235
 [11] _text_fill_string_matrix!(io::IOContext, table_str::Matrix{…}, ptable::PrettyTables.ProcessedTable, actual_columns_width::Vector{…}, display::PrettyTables.Display, formatters::Ref{…}, num_lines_in_row::Vector{…}, autowrap::Bool, cell_first_line_only::Bool, columns_width::Vector{…}, compact_printing::Bool, crop_subheader::Bool, limit_printing::Bool, linebreaks::Bool, maximum_columns_width::Vector{…}, minimum_columns_width::Vector{…}, renderer::Val{…}, vcrop_mode::Symbol)
    @ PrettyTables ~/.julia/packages/PrettyTables/E8rPJ/src/backends/text/fill.jl:81
 [12] _print_table_with_text_back_end(pinfo::PrettyTables.PrintInfo; alignment_anchor_fallback::Symbol, alignment_anchor_fallback_override::Dict{…}, alignment_anchor_regex::Dict{…}, autowrap::Bool, body_hlines::Vector{…}, body_hlines_format::Nothing, continuation_row_alignment::Symbol, crop::Symbol, crop_subheader::Bool, columns_width::Int64, display_size::Tuple{…}, equal_columns_width::Bool, ellipsis_line_skip::Int64, highlighters::Tuple{}, hlines::UnitRange{…}, linebreaks::Bool, maximum_columns_width::Int64, minimum_columns_width::Int64, newline_at_end::Bool, overwrite::Bool, reserved_display_lines::Int64, show_omitted_cell_summary::Bool, sortkeys::Bool, tf::PrettyTables.TextFormat, title_autowrap::Bool, title_same_width_as_table::Bool, vcrop_mode::Symbol, vlines::UnitRange{…}, border_crayon::Crayons.Crayon, header_crayon::Crayons.Crayon, omitted_cell_summary_crayon::Crayons.Crayon, row_label_crayon::Crayons.Crayon, row_label_header_crayon::Crayons.Crayon, row_number_header_crayon::Crayons.Crayon, subheader_crayon::Crayons.Crayon, text_crayon::Crayons.Crayon, title_crayon::Crayons.Crayon)
    @ PrettyTables ~/.julia/packages/PrettyTables/E8rPJ/src/backends/text/text_backend.jl:53
 [13] _print_table(io::IO, data::Any; alignment::Symbol, backend::Val{…}, cell_alignment::Nothing, cell_first_line_only::Bool, compact_printing::Bool, formatters::Nothing, header::Tuple{…}, header_alignment::Symbol, header_cell_alignment::Nothing, limit_printing::Bool, max_num_of_columns::Int64, max_num_of_rows::Int64, renderer::Symbol, row_labels::Nothing, row_label_alignment::Symbol, row_label_column_title::String, row_number_alignment::Symbol, row_number_column_title::String, show_header::Bool, show_row_number::Bool, show_subheader::Bool, title::String, title_alignment::Symbol, kwargs::@Kwargs{})
    @ PrettyTables ~/.julia/packages/PrettyTables/E8rPJ/src/print.jl:1005
 [14] _print_table
    @ ~/.julia/packages/PrettyTables/E8rPJ/src/print.jl:880 [inlined]
 [15] #pretty_table#62
    @ ~/.julia/packages/PrettyTables/E8rPJ/src/print.jl:771 [inlined]
 [16] pretty_table
    @ ~/.julia/packages/PrettyTables/E8rPJ/src/print.jl:740 [inlined]
 [17] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, tb::ReadStatTable{ReadStatColumns})
    @ ReadStatTables ~/.julia/packages/ReadStatTables/exgPH/src/table.jl:374
 [18] (::REPL.var"#68#69"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:383
 [19] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:679
 [20] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:369
 [21] display
    @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:388 [inlined]
 [22] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [23] #invokelatest#2
    @ ./essentials.jl:1030 [inlined]
 [24] invokelatest
    @ ./essentials.jl:1027 [inlined]
 [25] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:425
 [26] (::REPL.var"#70#71"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:394
 [27] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:679
 [28] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:392
 [29] (::REPL.var"#do_respond#93"{Bool, Bool, REPL.var"#106#118"{}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:1021
 [30] #invokelatest#2
    @ ./essentials.jl:1030 [inlined]
 [31] invokelatest
    @ ./essentials.jl:1027 [inlined]
 [32] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:2747
 [33] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:1446
 [34] (::REPL.var"#75#81"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:496
Some type information was truncated. Use `show(err)` to see complete types.
@jkrumbiegel
Copy link
Contributor Author

Ah it actually appears that the file is written, but the error happens when showing the resulting ReadStatTable. I can also read the file back in with t = ReadStatTables.readstat("test.xpt") and again only showing that object fails, not the reading itself.

@junyuan-chen
Copy link
Owner

@jkrumbiegel Thank you for reporting! I realize that since Julia DateTime is internally represented as Int64, conversion to integer has to happen at some point. The best thing for me to do seems to be having some rounding to the closest Millisecond. This will be addressed in #39 and come with v0.3.1 release soon.

@junyuan-chen junyuan-chen changed the title Millisecond precision for DateTimes InexactError for floating-point date/time values Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants