Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Heptazhou committed Nov 20, 2024
1 parent bbfb05c commit c8c99db
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI
on:
workflow_dispatch: ~
pull_request:
branches:
- "master"
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Exts"
uuid = "0b12d779-4123-4875-9d6c-e33c2e29e2c9"
authors = ["Heptazhou <zhou at 0h7z dot com>"]
version = "0.2.3"
version = "0.2.4"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Expand Down
9 changes: 5 additions & 4 deletions ext/FITSIOExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ module FITSIOExt
using Base.Threads: @spawn
using DataFrames: DataFrame
using Exts: SymOrStr, ensure_vector, lmap
using FITSIO: FITSIO, FITS, EitherTableHDU
using FITSIO: FITSIO, CFITSIO, FITS, EitherTableHDU

@doc " FITSIO.EitherTableHDU <- Union{ASCIITableHDU, TableHDU}" EitherTableHDU

"""
read(t::FITSIO.EitherTableHDU, DataFrame,
colnames = Tables.columnnames(t)) -> DataFrame
Read a DataFrame from the given ASCIITableHDU or TableHDU.
Read a DataFrame from the given table (of type `ASCIITableHDU` or
`TableHDU`).
"""
function Base.read(t::EitherTableHDU, ::Type{DataFrame},
colnames::AbstractVector{<:SymOrStr} = FITSIO.Tables.columnnames(t))
fits = t.fitsfile
f, n = FITSIO.fits_file_name(fits), t.ext
if 0 FITSIO.fits_file_mode(fits) # 0 => read-only, 1 => read-write
f, n = CFITSIO.fits_file_name(fits), t.ext
if 0 CFITSIO.fits_file_mode(fits) # 0 => read-only, 1 => read-write
throw(ArgumentError("FITS file must be opened in read-only mode"))
end
cols = map(lmap(String, colnames)) do colname
Expand Down
1 change: 1 addition & 0 deletions src/Exts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export VType
export @catch
export @noinfo
export @nowarn
export @S_str
export @try
export @trycatch
export
Expand Down
19 changes: 19 additions & 0 deletions src/Macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ for level ∈ ("info", "warn")
end
end

"""
@S_str -> Symbol
Create a [`Symbol`](@extref :type:Core.Symbol) from a literal string.
# Examples
```jldoctest
julia> S"Julia"
:Julia
julia> S"\$0 expands to the name of the shell or shell script."
Symbol("\\\$0 expands to the name of the shell or shell script.")
```
"""
macro S_str(string)
:(Symbol($string))
# https://man.archlinux.org/man/core/bash/bash.1#Special_Parameters
end

@eval begin
"""
@try expr default = nothing
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ end
@test_throws LoadError @eval @catch
@test_throws LoadError @eval @noinfo
@test_throws LoadError @eval @nowarn
@test_throws LoadError @eval @S_str
@test_throws LoadError @eval @try
@test_throws LoadError @eval @trycatch
@test_throws UndefVarError ∠
Expand Down Expand Up @@ -263,6 +264,7 @@ end
@test ErrorException("") == @trycatch error()
@test isnothing(@catch true)
@test isnothing(@try error())
@test S":" === :(:)
end

fi, i = mktemp()
Expand All @@ -284,7 +286,7 @@ end
@test df == read(tmp, DataFrame)
@test df == read(tmp, DataFrame, [:x, :y], skipstart = 1)
@test df == CSV.read(tmp, DataFrame)
@test dropmissing(DataFrame(x = [1, missing])) == DataFrame(x = [1])
@test dropmissing(DataFrame(x = [missing, 1])) == DataFrame(x = [1])
end

@testset "FITSIOExt" begin
Expand Down

0 comments on commit c8c99db

Please sign in to comment.