Coder Social home page Coder Social logo

Comments (5)

MaxGhenis avatar MaxGhenis commented on June 1, 2024 1

Interesting, thanks @hdoupe. Based on this and some more poking around the code, looks like this is how pandas treats fastparquet:

  • Include as a dep in environment.yml
  • Don't include in setup.py
  • Use an import_optional_dependency function in pandas.compat._optional, which is used elsewhere internally (this also specifies the minimum version for optional deps)
  • Call import_optional_dependency in to_parquet and read_parquet in parquet.py (through a couple intermediate steps)
  • In test_parquet.py, check if it's installed with a try statement and skip tests if it isn't

I'll mirror this approach.

from microdf.

hdoupe avatar hdoupe commented on June 1, 2024

Pandas handles its optional/soft fastparquet dependency like this:

In [1]: import pandas as pd                                                                                                                                                                   

In [2]: df = pd.read_parquet("matchups/statcast2018.parquet", engine="fastparquet")                                                                                                           
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-284dbcb9c5fc> in <module>
----> 1 df = pd.read_parquet("matchups/statcast2018.parquet", engine="fastparquet")

~/miniconda3/lib/python3.7/site-packages/pandas/io/parquet.py in read_parquet(path, engine, columns, **kwargs)
    293     """
    294 
--> 295     impl = get_engine(engine)
    296     return impl.read(path, columns=columns, **kwargs)

~/miniconda3/lib/python3.7/site-packages/pandas/io/parquet.py in get_engine(engine)
     42         return PyArrowImpl()
     43     elif engine == "fastparquet":
---> 44         return FastParquetImpl()
     45 
     46 

~/miniconda3/lib/python3.7/site-packages/pandas/io/parquet.py in __init__(self)
    139         # we need to import on first use
    140         fastparquet = import_optional_dependency(
--> 141             "fastparquet", extra="fastparquet is required for parquet support."
    142         )
    143         self.api = fastparquet

~/miniconda3/lib/python3.7/site-packages/pandas/compat/_optional.py in import_optional_dependency(name, extra, raise_on_missing, on_version)
     91     except ImportError:
     92         if raise_on_missing:
---> 93             raise ImportError(message.format(name=name, extra=extra)) from None
     94         else:
     95             return None

ImportError: Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.

In [3]:                                                                                                                                                                                       

If you wanted to do something like this, then you could add a note to the install instructions telling people that taxcalc should be installed separately.

One thing to note is that Pandas can still read parquet files without other packages like fastpaquet being installed.

from microdf.

MaxGhenis avatar MaxGhenis commented on June 1, 2024

For completeness, here's the current error when importing microdf without having taxcalc installed:

import microdf
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-15236528f5d7> in <module>()
----> 1 import microdf

1 frames
/usr/local/lib/python3.6/dist-packages/microdf/taxcalc.py in <module>()
      1 import microdf as mdf
----> 2 import taxcalc as tc
      3 
      4 
      5 def static_baseline_calc(recs, year):

ModuleNotFoundError: No module named 'taxcalc'

from microdf.

MaxGhenis avatar MaxGhenis commented on June 1, 2024

Importing microdf now works when taxcalc isn't installed.

from microdf.

MaxGhenis avatar MaxGhenis commented on June 1, 2024

Thanks again, @hdoupe for the guidance here!

from microdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.