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

Fix TableTraits functions failing on non-standard index #103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ jobs:
Python ${{ matrix.python-version }}
${{ matrix.os }} ${{ matrix.architecture }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- run: python -m pip install --upgrade pip
- run: python -m pip install pandas

- name: Setup julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.architecture }}
Expand All @@ -51,21 +51,11 @@ jobs:
env:
PYTHON: python

- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-

- uses: julia-actions/cache@v2
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v5
with:
file: ./lcov.info
files: ./lcov.info
flags: unittests
name: codecov-umbrella
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Pandas"
uuid = "eadc2687-ae89-51f9-a5d9-86b5a6373a9c"
version = "1.6.1"
version = "1.6.2"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
14 changes: 6 additions & 8 deletions src/tabletraits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ IteratorInterfaceExtensions.isiterable(x::DataFrame) = true
TableTraits.isiterabletable(x::DataFrame) = true

function TableTraits.getiterator(df::DataFrame)
col_names_raw = [i for i in Pandas.columns(df)]
col_names = Symbol.(col_names_raw)

column_data = [eltype(df[i])==String ? [df[i][j] for j=1:length(df)] : values(df[i]) for i in col_names_raw]
col_names = Symbol.(Pandas.columns(df))
column_data = ([df[i]...] for i in col_names)

return create_tableiterator(column_data, col_names)
end
Expand All @@ -19,10 +17,10 @@ TableTraits.supports_get_columns_copy_using_missing(df::DataFrame) = true

function TableTraits.get_columns_copy_using_missing(df::Pandas.DataFrame)
# return a named tuple of columns here
col_names_raw = [i for i in Pandas.columns(df)]
col_names = Symbol.(col_names_raw)
cols = (Array(eltype(df[i])==String ? [df[i][j] for j=1:length(df)] : df[i]) for i in col_names_raw)
return NamedTuple{tuple(col_names...)}(tuple(cols...))
col_names = Symbol.(Pandas.columns(df))
column_data = Tuple([df[i]...] for i in col_names)

return NamedTuple(col_names .=> column_data)
end

function _construct_pandas_from_iterabletable(source)
Expand Down
7 changes: 7 additions & 0 deletions test/test_tabletraits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ it3_collected = collect(IteratorInterfaceExtensions.getiterator(df3))
cols3 = TableTraits.get_columns_copy_using_missing(df3)
@test isequal(cols3, (a=[NaN,2.], b=["John", "Sally"], c=[3.2, NaN]))

# Create a non-standard index in the python representation
df4 = DataFrame(["a",]; index=[1,], columns=[:x])
cols4 = TableTraits.get_columns_copy_using_missing(df4)
@test length(cols4) == 1
it4 = IteratorInterfaceExtensions.getiterator(df4)
@test length(it4) == 1

end
Loading