Skip to content

Histogram doesn't work for pandas.Series #1253

Description

@seisman

Description of the problem

Full code that generated the error

import pygmt
import pandas as pd
import numpy as np

table = pd.read_csv("https://raw.githubusercontent.com/GenericMappingTools/pygmt/master/pygmt/tests/data/points.txt", sep=" ", header=None)

fig = pygmt.Figure()
fig.histogram(table[0], pen="1p", series=[0, 90, 10], frame=True)             # Fail
#fig.histogram(np.array(table[0]), pen="1p", series=[0, 90, 10], frame=True)  # Pass
fig.show()

I have to convert table[0] to a numpy array to make it work.

Full error message

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    fig.histogram(table[0], pen="1p", series=[0, 90, 10], frame=True)
  File "pygmt/pygmt/helpers/decorators.py", line 297, in new_module
    return module_func(*args, **kwargs)
  File "pygmt/pygmt/helpers/decorators.py", line 438, in new_module
    return module_func(*args, **kwargs)
  File "pygmt/pygmt/src/histogram.py", line 57, in histogram
    with file_context as infile:
  File "lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "pygmt/pygmt/clib/session.py", line 1159, in virtualfile_from_vectors
    rows = len(arrays[0])
TypeError: len() of unsized object

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PyGMT information:
  version: v0.3.2.dev82+g82ebbbc4.d20210412
System information:
  python: 3.8.5 (default, Sep  4 2020, 02:22:02)  [Clang 10.0.0 ]
  executable: /Users/XXX/.miniconda/bin/python
  machine: macOS-10.16-x86_64-i386-64bit
Dependency information:
  numpy: 1.20.1
  pandas: 1.2.3
  xarray: 0.17.0
  netCDF4: 1.5.6
  packaging: 20.9
  ghostscript: 9.53.3
  gmt: 6.2.0_522a350_2021.04.29
GMT library information:
  binary dir: /Users/XXX/.miniconda/bin
  cores: 8
  grid layout: rows
  library path: /Users/XXX/opt/GMT-master/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/XXX/opt/GMT-master/lib/gmt/plugins
  share dir: /Users/XXX/opt/GMT-master/share
  version: 6.2.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions