Hi! Realistically, what would it take to remove `n...
# improvement-ideas
t
Hi! Realistically, what would it take to remove
numpy
and
pandas
as required dependencies? AFAIK, they are currently there for backwards compatibility with plugin autoloading. Currently, this is a barrier to adoption in my case where I want to use Hamilton's lightweight features.> Older
pandas
and
numpy
features exist on some modules of the "main code path". The
import
statements could be moved inside the relevant functions / classes to make them lazy Is there a way to package the project such that
pip install sf-hamilton[core]
doesn't include those?
👍 2
s
can you instead uninstall those dependencies? If so, then yeah just making it so that hamilton doesn't break when they are not in the environment would be the work.
t
I currently can't use
sf-hamilton
as an optional dependency in
dlt
IMHO, depending on
pip install sf-hamilton
to have
pandas
installed is leaky dependency management. Removing
pandas
wouldn't be a breaking changes. The tricky situation is that Hamilton does
autoload_plugin=True
by default. Therefore, removing
pandas
becomes a breaking change in that case.
Is there any usage data on the following? •
hamilton.base.PandasDataFrameResult
•
hamilton.base.StrictIndexTypePandasDataFrameResult
•
hamilton.base.NumpyMatrixResult
•
hamilton.base.SimplePythonDataFrameGraphAdapter
•
hamilton.base.SimplePythonGraphAdapter
•
hamilton.base.DefaultAdapter
They seem to be the main / only culprit. IMHO, we should setup deprecation warnings and have a clear plan to: 1. remove
pandas
,
numpy
and
networkx
(in
visualization
extra, but is unused) dependencies 2. disable plugin autoloading by default Otherwise, the only solution would be forking the repo and distributing
sf-hamilton-core
, which seems less than ideal.
s
Either way to enable this we need to change the code so that things don't break if
numpy
and
pandas
isn't installed. Then we can figure something out with respect to the package -- for version <
2
. we could do something like
sf-hamilton-core
and then have
sf-hamilton
depend on it...
t
The lowest effort change is a single
.py
file that: • import hamilton registry • disable autoload • patches the
hamilton.base
module with a version that doesn't import
pandas
and
numpy
at the top-level. This could exist within the
apache/hamilton
monorepo. Should I spend some time opening a draft PR ?
s
to clarify, how would you plan to make this a backwards compatible change?
t
It would be a fun exercise in dynamic programming. In short: • in
apache/hamilton
, you create
hamilton-core/
• it has its own
pyproject.toml
that doesn't have pandas and numpy as deps •
pyproject.toml
with a directive to include
hamilton/
in its build ◦ a user that
pip install sf-hamilton-core
will get all of the
hamilton
source code, but is not depending on
sf-hamilton
explicitly •
hamilton-core/__init__.py
and its module hold no implementation, they simply import from the localized
hamilton
source code •
hamilton-core
will only reimplement the
hamilton.base
module, by moving the
pandas
and
numpy
imports to a lazy location •
hamilton-core
will need to add a test to check that all
sf-hamilton
objects can be imported • Going one-step further, the
hamilton-core/pyproject.toml
could be written in such a way that it produces a Python library with the name
hamilton
, making it a drop-in replacement. User experience: •
pip uninstall sf-hamilton
•
pip install sf-hamilton-core
• code should just work, but without the deps •
pip list
will show
sf-hamilton-core
instead of
sf-hamilton
I'm confident I can make it work. What I want to validate is if it has any chance of being merged. If not, I can simply fork the repo which is simpler and more robust
s
yeah I think as long as we're backwards compatible I don't see an issue. Otherwise I think this is a good question for the dev@hamilton mailing list -- since the mentors might have an opinion here -- they would need to be convinced at least from the release perspective -- less so whether it should be merged.
t
it works 🙂 I'm able to: • define the project dynamically in
setup.py
from the original
pyproject.toml
and remove the
pandas
and
numpy
deps •
pip install sf-hamilton-core
produces a drop-in replacement available via
import hamilton
• this new module has extension autoloading disabled by default and doesn't install pandas and numpy • this new module passes all tests (with
pandas
and
numpy
installed)
🙌 1
will open a PR tomorrow