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

AttributeError: module 'numpy' has no attribute 'unicode' #178

Open
seizethedata opened this issue Jan 10, 2023 · 1 comment
Open

AttributeError: module 'numpy' has no attribute 'unicode' #178

seizethedata opened this issue Jan 10, 2023 · 1 comment

Comments

@seizethedata
Copy link

seizethedata commented Jan 10, 2023

Hi!

I've stumbled into an issue and would love any help / suggestions. This run on a Python 3.8 on Mac M1.

I'm trying to run this code on my own data (tried it with ac gtfs too):

path = '/Milano/comune-di-milano_20160216_1409.zip'

# Automatically identify the busiest day and
# read that in as a Partidge feed
feed = pt.get_representative_feed(path)

# Set a target time period to
# use to summarize impedance
start = 7*60*60  # 7:00 AM
end = 10*60*60  # 10:00 AM

# Converts feed subset into a directed
# network multigraph
G = pt.load_feed_as_graph(feed, start, end) 

and get an error:

AttributeError: module 'numpy' has no attribute 'unicode'

Tried to reinstall everything and install from scratch, but to no avail.

The full output of the error is this: 
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 6
      2 path = '/Users/DANIEL/WORK/MIC-HUB/GTFS Milano/comune-di-milano_20160216_1409.zip'
      4 # Automatically identify the busiest day and
      5 # read that in as a Partidge feed
----> 6 feed = pt.get_representative_feed(path)
      8 # Set a target time period to
      9 # use to summarize impedance
     10 start = 7*60*60  # 7:00 AM

File /opt/homebrew/lib/python3.8/site-packages/peartree/paths.py:95, in get_representative_feed(file_loc, day_type)
     93 # Extract service ids and then trip counts by those dates
     94 try:
---> 95     service_ids_by_date = ptg.read_service_ids_by_date(file_loc)
     96     trip_counts_by_date = ptg.read_trip_counts_by_date(file_loc)
     98 # Raised by partridge if no valid dates returned

File /opt/homebrew/lib/python3.8/site-packages/partridge/readers.py:72, in read_service_ids_by_date(path)
     70 """Find all service identifiers by date"""
     71 feed = load_raw_feed(path)
---> 72 return _service_ids_by_date(feed)

File /opt/homebrew/lib/python3.8/site-packages/partridge/readers.py:156, in _service_ids_by_date(feed)
    153 results: DefaultDict[datetime.date, Set[str]] = defaultdict(set)
    154 removals: DefaultDict[datetime.date, Set[str]] = defaultdict(set)
--> 156 service_ids = set(feed.trips.service_id)
    157 calendar = feed.calendar
    158 caldates = feed.calendar_dates

File /opt/homebrew/lib/python3.8/site-packages/partridge/gtfs.py:16, in _read_file.<locals>.getter(self)
     15 def getter(self) -> pd.DataFrame:
---> 16     return self.get(filename)

File /opt/homebrew/lib/python3.8/site-packages/partridge/gtfs.py:48, in Feed.get(self, filename)
     46 df = self._cache.get(filename)
     47 if df is None:
---> 48     df = self._read(filename)
     49     df = self._filter(filename, df)
     50     df = self._prune(filename, df)

File /opt/homebrew/lib/python3.8/site-packages/partridge/gtfs.py:48, in Feed.get(self, filename)
     46 df = self._cache.get(filename)
     47 if df is None:
---> 48     df = self._read(filename)
     49     df = self._filter(filename, df)
     50     df = self._prune(filename, df)

File /opt/homebrew/lib/python3.8/site-packages/partridge/gtfs.py:102, in Feed._read_csv(self, filename)
     99 with open(path, "rb") as f:
    100     encoding = detect_encoding(f)
--> 102 df = pd.read_csv(path, dtype=np.unicode, encoding=encoding, index_col=False)
    104 # Strip leading/trailing whitespace from column names
    105 df.rename(columns=lambda x: x.strip(), inplace=True)

File /opt/homebrew/lib/python3.8/site-packages/numpy/__init__.py:284, in __getattr__(attr)
    281     from .testing import Tester
    282     return Tester
--> 284 raise AttributeError("module {!r} has no attribute "
    285                      "{!r}".format(__name__, attr))

AttributeError: module 'numpy' has no attribute 'unicode' 

@kuanb
Copy link
Owner

kuanb commented Nov 8, 2023

This is the issue: https://stackoverflow.com/questions/75069062/module-numpy-has-no-attribute-object
Looks like numpy v1.24 and greater do not support this pattern. See more here: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Looks like recommendation is to use unicode direction. Per the deprecation notes:

To give a clear guideline for the vast majority of cases, for the types bool, object, str (and unicode) using the plain version is shorter and clear, and generally a good replacement.

@kuanb kuanb closed this as completed Nov 8, 2023
@kuanb kuanb reopened this Nov 8, 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