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

transpose method errors #3295

Closed
emmaccode opened this issue Mar 4, 2023 · 1 comment
Closed

transpose method errors #3295

emmaccode opened this issue Mar 4, 2023 · 1 comment

Comments

@emmaccode
Copy link

version info
julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
transpose method errors

So I know that permutedims transposes a DataFrame fine, but I was curious and wanted to try the Base function transpose on a DataFrame for a recent piece I am doing on how Julia carries Base functions through its ecosystem, starring DataFrames. I was interested to find out that a transpose(::DataFrame) method exists. However, whenever this method is called on a DataFrame, the return is a MethodError for a MethodError. Meaning that even the MethodError is called wrong, have a look:

julia> transpose(df)
ERROR: MethodError: no method matching MethodError(::String)
Closest candidates are:
  MethodError(::Any, ::Any) at /opt/julia-1.6.3/julia-1.6.3/share/julia/base/boot.jl:343
  MethodError(::Any, ::Any, ::UInt64) at /opt/julia-1.6.3/julia-1.6.3/share/julia/base/boot.jl:340
Stacktrace:
 [1] transpose(::DataFrame; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ DataFrames ~/.julia/packages/DataFrames/3mEXm/src/abstractdataframe/reshape.jl:531
 [2] transpose(::DataFrame)
   @ DataFrames ~/.julia/packages/DataFrames/3mEXm/src/abstractdataframe/reshape.jl:531
 [3] top-level scope
   @ REPL[6]:1

Is there any intention to consider the transpose(::DataFrame) method? Am I simply calling it wrong? Either way, it seems there is a problem here with the MethodError if I am doing something wrong. Perhaps I will have a look and maybe PR if I have time later. Thanks.

@bkamins
Copy link
Member

bkamins commented Mar 4, 2023

There are the following issues with your code.

  1. You are using DataFrames.jl 0.22.7. I strongly recommend you not to use it. Current version is 1.5.0. 0.22.7 was released 2 years ago, and since then a breaking 1.0 release was made. In short: unless you have a reason to do so please consider updating DataFrames.jl to latest version.

  2. On current version of DataFrames.jl 1.5.0 you will get the following error:

julia> transpose(df)
ERROR: ArgumentError: `transpose` not defined for `AbstractDataFrame`s. Try `permutedims` instead

which tells you what to do.

  1. Why transpose is not defined for DataFrame? The answer is in transpose docstring:

This operation is intended for linear algebra usage - for general data manipulation see permutedims, which is non-recursive.

As you can see transpose is reserved in Julia for linear algebra (in particular - it is recursive). permutedims is an appropriate function to use with DataFrame objects (data frames do not support linear algebra operations). If you want an object that is compatible with linear algebra do Matrix(df) and then you can transpose the resulting matrix.

@bkamins bkamins closed this as completed Mar 4, 2023
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